Highlight and clickdetector messing up

Hello, so I am trying to do a very basic script where if you hover on a model/object, it will get a highlight.

There is a weird bug happening that when you hover on a object, another object with the same script will get highlighted too.


image

I didn’t really do much trying to solve the issue because the script is already so basic that i don t think i can really do something.

here is the script used on all the models:

local prompt = script.Parent.ClickDetector
local highlight = script.Parent.Highlight

prompt.MouseHoverEnter:Connect(function()
	highlight.OutlineTransparency = 0
end)

prompt.MouseHoverLeave:Connect(function()
	highlight.OutlineTransparency = 1
end)

image

I also tried doing a little fade for the highlight when you hover your mouse on the item but it was too glitchy and i gave up.

2 Likes

From what I know, highlights are really glitchy. Also, you should try enabled/disabling the highlight on mouseleave and mouseEnter functions.

2 Likes

I updated the scripts and the problem still occurs.

image

2 Likes

hmm. I don’t know why it does that. But I really recommend to have a localscript in startergui or playerscripts that every rendersteps it detects if a mouse is hovering over a part with the “Highlightable” tag or something. Then, at the start of the script create a highlight and parent it to the script, and when the mouse is hovering over it make the highlight addonore the part.

2 Likes

I ll wait a bit to see if maybe others have other ideas, but if not, i ll most likely try to do that. Thanks for the help!

1 Like

Yeah, sadly no one responded so i’ll try to do that, i’ll still accept ideas if anyone is willing to help.

You should be handling these effects on the client side, and you shouldn’t be needing to put a script into every single model.

I would recommend using CollectionService, tagging the parts you want to be highlighted, and in StarterPlayerScripts, modify it as needed in a LocalScript.

Code (make sure to tag all parts you want to be highlighted when hovered with “Highlightable”):

--//Services
local CollectionService = game:GetService("CollectionService")

--//Functions
local function InitializeHighlightable(part)
	local prompt = part.ClickDetector
	local highlight = part.highlight
	
	prompt.MouseHoverEnter:Connect(function()
		highlight.OutlineTransparency = 0
	end)

	prompt.MouseHoverLeave:Connect(function()
		highlight.OutlineTransparency = 1
	end)
end

CollectionService:GetInstanceAddedSignal("Highlightable"):Connect(InitializeHighlightable)

for i, highlightable in CollectionService:GetTagged("Highlightable") do
	task.spawn(InitializeHighlightable, highlightable)
end

Put this LocalScript in StarterPlayerScripts:
image

1 Like

Hello, I do not see any major problem with this glitch, I have no idea why It happens but there are a few things that might be causing the issue:

  1. Multiple Scripts If you have multiple copies of this script in different models, and they all reference the same Highlight object, they could interfere with each other. Ensure that each model has its own unique Highlight object.

  2. Event Overlap : If the mouse quickly moves between objects, the MouseHoverLeave event of one object might not trigger before the MouseHoverEnter event of another object. This can cause multiple objects to appear highlighted.

Also, consider using tweens that may be helpful:

local TweenService = game:GetService("TweenService")

local prompt = script.Parent.ClickDetector
local highlight = script.Parent.Highlight

local fadeIn = TweenService:Create(highlight, TweenInfo.new(0.5), {OutlineTransparency = 0})
local fadeOut = TweenService:Create(highlight, TweenInfo.new(0.5), {OutlineTransparency = 1})

prompt.MouseHoverEnter:Connect(function()
    fadeOut:Cancel() -- Cancel any ongoing fade-out
    fadeIn:Play()
end)

prompt.MouseHoverLeave:Connect(function()
    fadeIn:Cancel() -- Cancel any ongoing fade-in
    fadeOut:Play()
end)

This script uses the TweenService to smoothly transition the OutlineTransparency property of the Highlight object. The Cancel method ensures that if a fade-in or fade-out is already in progress, it will stop, ensuring smoother transitions. I hope any of this information helps! :slight_smile:

1 Like

This doesn’t solve the problem of Multiple Scripts or Event Overlap, I’m assuming you just asked ChatGPT to answer though.

1 Like

pretty sure if you put a highlight into a model it’ll highlight the whole model, you probably just have duplicates in the same model

I already did help him earlier, you can scroll up easily.

Yeah, it doesn’t. What does matter though is you giving them scripts that do not solve the problem. It would’ve been fine if the scripts you provided actually solved his problem, but all you did was make it more complicated by adding TweenService. It just wastes the OP’s time when they have to try a script that was written without even intending to fix the problem.

Not sure if you meant to be rude with this, but the whole purpose of a forum is to discuss.

1 Like

Hello, thank you very much for the code, I tried it, but it s not working, most likely because i did something wrong, i tagged the model as highlightable but the highlight isn t showing.

Could you show the explorer? And also turn on View mode with tag editor?

I also want to know, are you tagging parts that have a ClickDetector and Highlight? Or are you tagging a model with every single part?

1 Like

Thank you for the idea, i will only use one script and after the problem will be solved i ll use tweens for the smooth transition!

I am trying to highlight the whole model, not just a part

image

You named the tag wrong.

It’s supposed to be:
“Highlightable”

Not:
“HIghlightable”

1 Like

Wow, i m so dumb. Anyway, this solved the problem, sorry for causing inconveniences. Thank you SO much for helping me!
Edit: I accidentally put the wrong response as solution, but I put it on your initial message now

1 Like

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