i’m having an issue with my selection system thingymabob where for some things, the highlight just isn’t visible even if the properties change
here’s the section of the code that changes/creates the highlight:
while wait() do
for _,v in pairs(workspace.Interactable:GetChildren()) do
if not table.find(interactables,v) then
table.insert(interactables,v)
local highlight = Instance.new("Highlight")
local cd = v:WaitForChild("ClickDetector")
highlight.FillTransparency = 1
highlight.FillColor = Color3.fromRGB(255,255,255)
highlight.OutlineTransparency = 1
highlight.Name = v.Name.." Select Highlight"
highlight.Parent = v
highlight.Adornee = v
cd.MouseHoverEnter:Connect(function(p)
if p == plr then
ts:Create(highlight,TweenInfo.new(.1),{FillTransparency = .6}):Play()
end
end)
cd.MouseHoverLeave:Connect(function(p)
if p == plr then
ts:Create(highlight,TweenInfo.new(.1),{FillTransparency = 1}):Play()
end
end)
I think the problem might be the while loop. Let’s say you have your mouse within the interactable object, the while loop is going to be constantly running those MouseHoverEnter and MouseHoverLeave functions.
My suggestion is to entirely get rid of the while loop. If you are worried about new objects being added to the folder and that they won’t have the highlight functionality, you can connect the folder to a child added event and update the new object.
local interactables = workspace.Interactable
interactables.ChildAdded:Connect(function(object)
local highlight = Instance.new("Highlight")
local cd = object:WaitForChild("ClickDetector")
highlight.FillTransparency = 1
highlight.FillColor = Color3.fromRGB(255,255,255)
highlight.OutlineTransparency = 1
highlight.Parent = object
highlight.Adornee = object
cd.MouseHoverEnter:Connect(function(p)
if p == plr then
ts:Create(highlight,TweenInfo.new(.1),{FillTransparency = .6}):Play()
end
end)
cd.MouseHoverLeave:Connect(function(p)
if p == plr then
ts:Create(highlight,TweenInfo.new(.1),{FillTransparency = 1}):Play()
end
end)
end)
but it checks if they’re in a table and adds them to it if they aren’t meaning that it technically only runs once. the reason i do this in the first place is b/c some of the objects don’t get rendered if they’re too far away
if not table.find(interactables,v) then
table.insert(interactables,v)
Now that I read your code again, I understand what you mean, there’s an if statement to check if the object is in the table or not… Whoops!
I recommend using a for loop originally to give all objects that highlight functionality. And then a childAdded event to the folder after to give the highlight to any future objects that get added to the folder.
But before you try any of that, did you check if the if statements in your mouse hover connections work?
thank you for the help, but i managed to figure it out on my own! apparently, there’s a limit to how many highlights you can have in a game, so i just made a single highlight that gets parented to the object you’re hovering over rather than having an individual highlight for all of them, and now it works great.