How can I make this script work? I made a older version but it required the part to have a highlight as a children and i wanna create a new highlight when you hover since there is a limit for how many highlight you can have at once. I can t figure how to do it. Any amount of help will help a lot, thanks!
Edit: I don’t get any errors, just the infinite yield thing from waitforchild
--//Services
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
--//Functions
local function InitializeHighlightable(part)
local prompt = part.ClickDetector
local highlight = part:WaitForChild("Highlight")
local value = workspace.Values.HighlightValue.Value
local originalTransparency = 1
local targetTransparency = 0
local tweenInfo = TweenInfo.new(0.3) -- Adjust the duration as needed
local function Create()
local newpart = Instance.new("Highlight")
newpart.FillTransparency = 1
newpart.OutlineTransparency = 1
newpart.DepthMode = Enum.HighlightDepthMode.Occluded
newpart.Parent = part
end
local function Destroy()
part:FindFirstChildOfClass("Highlight"):Destroy()
end
local function TweenTransparency()
local tween = TweenService:Create(highlight, tweenInfo, {
OutlineTransparency = targetTransparency
})
tween:Play()
end
prompt.MouseHoverEnter:Connect(function()
if value == true then
Create()
targetTransparency = 0
TweenTransparency()
end
end)
prompt.MouseHoverLeave:Connect(function()
if value == true then
targetTransparency = 1
TweenTransparency()
wait(0.3)
Destroy()
end
end)
end
CollectionService:GetInstanceAddedSignal("Highlightable"):Connect(InitializeHighlightable)
for _, highlightable in ipairs(CollectionService:GetTagged("Highlightable")) do
task.spawn(InitializeHighlightable, highlightable)
end
Yeah, i still can’t figure it out.
Is the script you posted you’re current one?
When running InitializeHighlightable, you assigning the variable highlight as if it is a child of the created part. You will want to create a highlight instead of waiting for it.
Also, the variable highlight is not even used in this script, so you could delete it with no issue.
Hello, thank you for the help! The script is the new version that i am trying to fix, but it’s not really working. As for your response, if i create the highlight in initializehighlightable, wont that create one instantly for every part with the specific tag? If thats true then if i have a number of highlight instances over the limit wont that disable them?
Your code will never run completely because local highlight = part:WaitForChild("Highlight") will yield forever.
You should consider simply declaring local highlight, without setting any value, and then upon running Create() set the value of highlight to the new highlight you’ve created.
I would make highlight a variable, use Debris:AddItem() and return the tween or the highlight in their functions. That may softcode things out.
You’re also using ipairs() instead of directly iterating, I’m not sure which is faster, but just saying you should benchmark and test performance on both.
The local highlight part is not neccessary,
Also, you can use coroutine or task.spawn() if you just want to remove the highlight, but I don’t reccomend doing this, since it may bug things out.
But, great awnser!
Hello, thanks for helping! It is better now, but it still sometimes works when hovering and sometimes doesnt.
Thanks for responding! Your idea sounds promising, but i m not familiar with Debris service.
Debris:AddItem() destroys objects after a specific amount of seconds.
I’m not sure if Debris has any other functionality.
wsg man,
good effort on the script so far. i think the problem is that u dont have adornee. this is a script i did from following a highlight tutorial i think its somewhere along ur lines. theres no need to create a new highlight everytime u hover over something. theres an adornee property right and u set the adornee to the part u want to highlight and when the mouse leaves the part, the adornee will be set to nil. take a look. hopefully this helps:
local script: (u create a tag in the part/model u want highlighted. i recommend using tageditor) 
local mouse = game.Players.LocalPlayer:GetMouse()
local cs = game:GetService("CollectionService")
mouse.Move:Connect(function()
script.Highlight.Adornee = nil
if not mouse.Target then script.Highlight.Adornee = nil return end
if cs:HasTag(mouse.Target, "highlightable") then
script.Highlight.Adornee = mouse.Target
return
elseif cs:HasTag(mouse.Target.Parent, "highlightable") then
script.Highlight.Adornee = mouse.Target.Parent
return
end
end)
Hello, the script works well, it adornees the highlight to the part, but it doesn’t show. Im pretty sure i know how to re-write the script to work.
i think it could be something to do with the properties of the highlight instance. i could be wrong but mess around w the properties