#How Can I Make A Script So Where I Hover Over Another Player, It Shows Their Username On a TextLabel
1 messages · Page 1 of 1 (latest)
You'll probably need to know how to do that first I guess and um my idea was:
You'll need a way to detect if the mouse is even trying to hover onto anything, so you'll need to listen to when the mouse moves
Then you'll need to know if there are any instances in the 3D world that the mouse is hovering on, so you'll need to use either mouse.Target or Raycasting. For Raycasting, you'll need to convert the mouse 2D position into 3D world coordinates, by using ViewportPointToRay so that you'll get a Ray from the camera's position. Then that Ray can be used for Raycasting by using its Origin and Direction (multiplied by a number since it's a unit vector). Then yeah you can do some traditional raycasting. Basically, this is an alternative to mouse.Target, by getting the current mouse position in 3D coordinates, then casting a Ray from the camera's position to those coordinates
Then um you'll probably want to check if it even is a player. We can check it by checking if the instance that was detected is parented to a player character, by using GetPlayerFromCharacter, but accessories contain baseparts too, so you'll need to use FindFirstAncestorOfClass (Model) to ignore these type of things. Then um you can check if GetPlayerFromCharacter returns a player, and if it does, you'll have the target and yeah
Then um your logic of displaying the username is up to you
I hope what I say is true by the way, I haven't really fact checked anything
But can he do all of this by himself or he gonna do some vibe coding?
I can do it, I just didnt really understand where to start.
ellie is very right but i would probably link it to a heartbeat event, reason being if another player moves to where the local players mouse is it will detect that (waiting till local player moves their mouse wont)
A RenderStepped would be preferable, and um, i feel like raycasting/logic every/prior frame isn't really necessary, that's why i suggested to use UIS for listening the mouse movement. But then again, that can be a viable option just to ensure if the mouse is already hovering an existing player, but yeah it's up to him whether he wants that feature or not but thanks for suggesting though!