Hello, I am working on a script that highlights a player’s character when you’re hovering over it with your mouse. The issue is, sometimes when my mouse is not on a player anymore the highlight remains.
I have no idea how to fix this so any help will be appreciated!
Code:
local Mouse = LocalPlayer:GetMouse()
local HighlightedChar
local function HighlightGive(thing)
HighlightedChar = thing
local Highlight = Instance.new("Highlight")
Highlight.OutlineColor = Color3.fromRGB(24, 205, 255)
Highlight.FillColor = Color3.fromRGB(42, 163, 255)
Highlight.Parent = thing
end
local function HighlightRemove()
if not HighlightedChar then return end
local Highlight = HighlightedChar:FindFirstChildOfClass("Highlight")
if Highlight then Highlight:Destroy() end
end
RunService.RenderStepped:Connect(function()
if not Mouse.Target then return end
if Mouse.Target.Parent:FindFirstChildOfClass("Humanoid") then
HighlightGive(Mouse.Target.Parent)
else
print("no")
HighlightRemove()
end
end)