Highlight not working when hovered over rig accessories

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local CollectionService = game:GetService("CollectionService")

local function withinActivationDistance(target)
	local character = player.Character
	if not character or not character:FindFirstChild("HumanoidRootPart") then
		return false
	end
	local rootPart = character.HumanoidRootPart
	local targetPosition = target.Position
	return (rootPart.Position - targetPosition).Magnitude <= 25
end

mouse.Move:Connect(function()
	if not mouse.Target then 
		script.Highlight.Adornee = nil 
		return 
	end

	local target = mouse.Target
	if withinActivationDistance(target) then
		if CollectionService:HasTag(target, "Highlightable") then
			script.Highlight.Adornee = target
			return
		elseif CollectionService:HasTag(target.Parent, "Highlightable") then
			script.Highlight.Adornee = target.Parent
			return
		end
	end

	script.Highlight.Adornee = nil
end)

Does anyone know why is this happening? When hovering over accessories, it kinda stops the highlight

I recommend using RunService BindToRenderStepped over mouse.Move as the player’s character can always move (jump/move/fall) without the camera moving.

That has to do with the accessories not being directly Parented to the character. It’s just a simple fix like so:

if CollectionService:HasTag(target, "Highlightable") then
	script.Highlight.Adornee = target
	return
elseif CollectionService:HasTag(target.Parent, "Highlightable") then
	script.Highlight.Adornee = target.Parent
	return
elseif CollectionService:HasTag(target.Parent.Parent, "Highlightable") 
	script.Highlight.Adornee = target.Parent
	return
end

You can also make use of a for loop like so:

for _ = 1,3 do
	if CollectionService:HasTag(target, "Highlightable") then
		script.Highlight.Adornee = target
		return
	end
	if not target.Parent then break end
	target = target.Parent
end
1 Like
local player = game.Players.LocalPlayer
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")

local function withinActivationDistance(target)
	local character = player.Character
	if not character or not character:FindFirstChild("HumanoidRootPart") then
		return false
	end
	local rootPart = character.HumanoidRootPart
	local targetPosition = target.Position
	return (rootPart.Position - targetPosition).Magnitude <= 25
end

local function findRig(target)
	local rig = target
	while rig and not rig:IsA("Model") do
		rig = rig.Parent
	end
	return rig
end

local function isHighlightable(target)
	return CollectionService:HasTag(target, "Highlightable")
end

RunService.RenderStepped:Connect(function()
	local mouse = player:GetMouse()
	if not mouse.Target then
		script.Highlight.Adornee = nil
		return
	end

	local target = mouse.Target
	local rig = findRig(target)

	if rig and withinActivationDistance(target) then
		if isHighlightable(rig) then
			script.Highlight.Adornee = rig
		else
			script.Highlight.Adornee = nil
		end
	else
		script.Highlight.Adornee = nil
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.