Issues with Highlights

I was making an item pickup system which basically consists of a script in a model that is a fake clone of a tool (like a knife). It has a clickdetector and a highlight inside of it. When the mouse hovers over it it enables the Highlight and when it leaves, it disables.

My issue is that I also have drawers using a similar script on their handles. It enables a highlight on the handle then opens when clicked. For someone reason the highlight appears on multiple object, for example when I hover over a handle, both the handle and the knife get highlighted.
robloxapp-20231020-1340528.wmv (3.5 MB)

Solutions I’ve tried was to check for any other scripts that could be interfering, didn’t find any. My only idea is that it could be an issue with Roblox itself.

Drawer Script:

local cd = script.Parent.Union.ClickDetector
local highLight = script.Parent.Union.Highlight

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TweenService = game:GetService("TweenService")

local openTween = TweenService:Create(script.Parent.Union, TweenInfo.new(0.5), {Position = Vector3.new(126.519, 1.317, 31.589)})
local closeTween = TweenService:Create(script.Parent.Union, TweenInfo.new(0.5), {Position = Vector3.new(126.519, 1.317, 29.589)})

cd.MouseHoverEnter:Connect(function(Player)
	highLight.Enabled = true
end)

cd.MouseHoverLeave:Connect(function(Player)
	highLight.Enabled = false
end)

cd.MouseClick:Connect(function(Player)
	if script.Parent.Union.Position == Vector3.new(126.519, 1.317, 29.589) then
		openTween:Play()
	else
		closeTween:Play()
	end
end)

Item Script:

local cd = script.Parent.Union.ClickDetector
local highLight = script.Parent.Union.Highlight

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TweenService = game:GetService("TweenService")

local openTween = TweenService:Create(script.Parent.Union, TweenInfo.new(0.5), {Position = Vector3.new(126.519, 2.607, 31.589)})
local closeTween = TweenService:Create(script.Parent.Union, TweenInfo.new(0.5), {Position = Vector3.new(126.519, 2.607, 29.589)})

local tool = game.ReplicatedStorage.Donut:Clone()

cd.MouseHoverEnter:Connect(function(Player)
	highLight.Enabled = true
end)

cd.MouseHoverLeave:Connect(function(Player)
	highLight.Enabled = false
end)

cd.MouseClick:Connect(function(Player)
	if script.Parent.Union.Position == Vector3.new(126.519, 2.607, 29.589) then
		openTween:Play()
	else
		closeTween:Play()
	end
end)

Thanks in advance.

1 Like

First, turn on the Show Decomposition Geometry in Studio settings just in case, to see how where exactly collision boxes are. Either way, you could use raycasting to find the closest item to highlight, this might make things much easier in the future.

However, I also had similar highlight-related issues which went away after I started adding highlight to the object of interest when it’s hovered and destroying it after hover ends. Worked much better than just having toggling Enabled on the Highlights that were pre-added.

2 Likes

Thanks for the tips, I’ll look into them and if I have any problems I’ll reply.

(also crazy i was just watching ur tiktok, i like ur game)

1 Like

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