Am I crazy or can you not add a highlight to a player?!

What I am trying to do is simple: Add a highlight to a player, that everyone can see. I thought this was as simple as putting a highlight under a player’s character model just like you would do with a Rig. But apparently I am wrong?? Here is my code (on a server script):


local function applyHighlight(char, apply)
	if apply then
		local highlight = Instance.new("Highlight")
		highlight.Adornee = char
		highlight.Parent = char
	else
		local highlight = char:FindFirstChild("Highlight")
		if highlight then
			highlight:Destroy()
		end
	end
end

afkEvent.OnServerEvent:Connect(function(player, afkToggle)
	local char = player.Character
	if not char then return end
	local hum = char:FindFirstChildOfClass("Humanoid")
	if not hum then return end

	if afkToggle == false then
		statRecompute.recompute(player)
		applyHighlight(char, false)
	else
		hum.MaxHealth = math.huge
		hum.Health = math.huge
		applyHighlight(char, true)
	end
end)

The highlight gets placed under the character’s model correctly, the Adornee is set, it is not transparent (stock highlight settings), it is set to AlwaysOnTop, no errors are thrown, and I see nothing on the character. I tried even using a local script to do this, same result.

I know I can put the highlight into StarterCharacterScripts and that will work, but that doesn’t show up for anyone else on the server, that is not the outcome I need. Am I crazy or can you actually not do this?

Highlights have a limit of 31 instances with additional instances not being rendered. Does your game use a lot of highlights? Keep in mind disabled and fully transparent highlights also count towards this limit. You can type classname:Highlight in the explorer to quickly count the number of highlights present.

1 Like

Make the highlight render on the client and only for the characters the player can see or is most likely to see. Figure out a way to calculate a score of how important it is to render a highlight given its position relative to the player, then sort in descending order and only render the top 31 of them.

Also add an update function that runs on Heartbeat but only updates/rerenders the highlights if the results are different than the previous checked frame(so something changed, like a character moving too far away from the player or leaving). Also don’t remove all highlights and re-add them every time, just change the ones that are different. Basically only remove highlights from characters that no longer have them and add highlights to players that didn’t have them previously(so you reduce lag compared to removing and adding everything per frame).

In fact now that I think about it you can be really confident that most of the time only a single highlight will be either removed or added per frame. You could take advantage of that to simplify some of the code.

1 Like

Thank you, I did not know this was a thing, I do in fact have a lot of highlights in my game.

For some use cases, you might be able to stretch things a bit by using a single Highlight instance for a group of items, by putting them all in a Model that has a single Highlight instance child. Of course this only works if you want the same highlight colors and transparencies on all of the objects, but that’s sometimes the case. You can dynamically re-parent things into a Model with a Highlight to add/remove them from being highlighted.

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