This code sets up a system that highlights the player’s character when the mouse hovers over a target within a certain distance. It starts by retrieving the RunService
and Players
services from the game. It then gets a reference to the local player and the player’s mouse.
To create the highlight effect, an instance Highlight
is created with the desired appearance properties such as outline color, fill color, outline transparency, and fill transparency. This highlight part is named “HoverHighlight” and is initially parented to the player’s character.
The code then connects a function to the RunService.RenderStepped
event, which is triggered on each frame update. Within this function, it checks if the mouse is hovering over a target by retrieving the Mouse.Target
. If the target exists and has a child named “Humanoid”, it proceeds to calculate the distance between the target and the player’s character using the Magnitude
property of the vector difference.
If the distance is within the specified threshold (50 units in this example), the highlight is shown by parenting it to the player’s character. Otherwise, if the distance exceeds the threshold, the highlight is hidden by removing its parent.
By continuously checking for mouse target changes and updating the highlight visibility accordingly, this code provides a dynamic visual indication when the mouse hovers over valid targets within the specified distance from the player’s character.
Reviews
There are no reviews yet.