Highlight Implementation Issues

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I’m wanting to create a simple effect where parts are added / removed from a global highlight model with the corresponding highlight being applied / removed appropriatly.

  2. What is the issue?
    By default, it seems highlights do not apply to new parts being inserted into a model. The same also seems to apply to items being removed from a model with the highlight applied. This causes issues with the system where I’m hoping to simply reparent parts / models in and out as needed to apply the highlight effect while still remaining under the 31 instance limit.

  3. What solutions have you tried so far?
    I’ve attempted to bypass this by creating a new highlight and deleting the old one upon ChildAdded / ChildRemoved. This either results in the highlight simply not being removed, or a strange flickering effect that words fail to describe, all seemingly depending on if a task.wait() is present or not. The only solution I’ve potentially found is setting the parent of the part to nil, waiting a task.wait(), then reparenting, but that causes an undesired flicker effect and could cause potential script errors.

I am looking for ANY potential aid in this, as Highlights are still relatively new to me and seem very interesting to integrate into my game.

local highlightModel = Instance.new("Model")
highlightModel.Name = "HighlightSetup"
highlightModel.Parent = game:GetService("Workspace")

local newHighlight = script.Outline:Clone()
newHighlight.Adornee = highlightModel
newHighlight.Parent = highlightModel

local function updateHighlight(item)
	if not item:IsA("Highlight") then
		local oldHighlight = newHighlight
		newHighlight = script.Outline:Clone()
		newHighlight.Adornee = highlightModel
		newHighlight.Enabled = true
		newHighlight.Parent = highlightModel
		
		oldHighlight.Parent = nil
		oldHighlight.Adornee = nil
		oldHighlight.Enabled = false

		oldHighlight:Destroy()
	end
end
1 Like

One possible solution you may want to consider is to use the descendants() method of the model to iterate through all the parts in the model and apply the highlight effect to each part individually. This way, the highlight effect will be applied to new parts as they are added to the model and removed from removed parts as they are removed from the model.

Here’s an example of how you could modify your existing code to apply the highlight effect to all the parts in the model:

local highlightModel = Instance.new("Model")
highlightModel.Name = "HighlightSetup"
highlightModel.Parent = game:GetService("Workspace")

local function applyHighlightEffect(item)
	if not item:IsA("BasePart") then
		return
	end

	local highlight = Instance.new("Highlight")
	highlight.Name = "Highlight"
	highlight.Parent = item
	highlight.Enabled = true
end

local function removeHighlightEffect(item)
	if not item:IsA("BasePart") then
		return
	end

	local highlight = item:FindFirstChildOfClass("Highlight")
	if highlight then
		highlight:Destroy()
	end
end

-- Apply highlight effect to all parts in the model
for _, item in ipairs(highlightModel:GetDescendants()) do
	applyHighlightEffect(item)
end

-- Listen for new parts added to the model
highlightModel.DescendantAdded:Connect(function(item)
	applyHighlightEffect(item)
end)

-- Listen for parts removed from the model
highlightModel.DescendantRemoving:Connect(function(item)
	removeHighlightEffect(item)
end)

This code will apply the highlight effect to all the parts in the model when the script runs, and will listen for new parts added to the model and apply the highlight effect to them as well. It will also listen for parts removed from the model and remove the highlight effect from them.

1 Like

One trick I’ve found to coerce Highlight objects to properly highlight new objects is to throw a Humanoid into the model you want highlighted. This still causes some flickering, but only on the specific parts whose parents changed. The flickering is less noticeable in most cases, and it stems from the Humanoid rather than the Highlight, since it will happen even if there is no Highlight object.

After playing around some more, I’ve found that you may be able to get the Highlight to cooperate without any flicker whatsoever by even simply throwing the Humanoid straight into the workspace, but I personally would be worried about potential side effects of that. I’m not positive there are any, but it just seems like something that would have unforeseen consequences.

1 Like

2 Years later and this is still an issue. Encountering this has made me realize how bugged highlights really are. Idk how they are even on Prod.

2 Likes

Your solution is crazy and it works lol

local function update(child)
	if child:FindFirstChildOfClass("Humanoid") then
		return
	end
	local hum = Instance.new("Humanoid")
	hum.Parent = child
	hum:Destroy()
end
adornee.ChildAdded:Connect(function(k)
	update(k)
end)
adornee.ChildRemoved:Connect(function(k)
	update(k)
end)

This is what i have to do to every adornee for each of my highlights :confused: Roblox fix this!

2 Likes

Yep. I have that disabling and enabling the highlight sometimes works, as well as resetting the adornee. I’m at least glad I’m not the only one with these issues… :p

image

1 Like

I’ve found a solution!
image

highlightModel is just the model that all your parts that you want to highlight are apart of.
Just have the highlight under workspace instead of the model itself. Not sure why this works, but it does.
Unfortunately makes my workspace messy :c

2 Likes

I have them parented to replicated storage lol. The humanoid hacky fix works for me though, i’ve tried changing the adornee/enabled back and forth and i found that to not work sometimes. The highlight will still be on models not parented to its adornee until i select it in studio explorer

Someone needs to file a bug report for us :sweat_smile: