Trouble with local highlights

Hello, I am trying to make a script where if the client receives a signal, it highlights all nearby ores and their rarity colors. This is my script:

game.ReplicatedStorage.Events.HighlightOres.OnClientEvent:Connect(function()
	if canSpelunk == true then
		script.Parent.Highlights:ClearAllChildren()
		canSpelunk = false
		script.activate.PlaybackSpeed = math.random(5,15)/10
		script.activate:Play()
		for i,ore in pairs(workspace.possibleOreSpots:GetDescendants()) do
			if ore:FindFirstChild("isOre") then
				local rarity = ore.rarityForSpelunkers.Value
				if rarity == "common" then
					c = Color3.fromRGB(255,255,255)
				elseif rarity == "rare" then
					c = Color3.fromRGB(0,0,255)
				elseif rarity == "epic" then
					c = Color3.fromRGB(170, 0, 255)
				elseif rarity == "legendary" then
					c = Color3.fromRGB(255, 170, 0)
				elseif rarity == "mythical" then
					c = Color3.fromRGB(255, 0, 70)
					c = Color3.fromRGB(255, 0, 70)
				elseif rarity == "exotic" then
					c = Color3.fromRGB(255, 255, 0)
				elseif rarity == "ethereal" then
					c = Color3.fromRGB(0, 255, 255)
				elseif rarity == "celestial" then
					c = Color3.fromRGB(25, 0, 100)
				end
				local h = script.Highlight:Clone()
				h.Adornee = ore
				h.FillColor = c
				h.OutlineColor = c
				h.Enabled = true
				h.Parent = script.Parent.Highlights
			end
		end

	end
	task.wait(15)
	for i,h in pairs(script.Parent.Highlights:GetChildren()) do
		if h:IsA("Highlight") then
			game.TweenService:Create(h,TweenInfo.new(15,Enum.EasingStyle.Quint,Enum.EasingDirection.In),{FillTransparency = 1, OutlineTransparency = 1}):Play()
		end
	end
	task.wait(15)
	canSpelunk = true
end)

But, for some reason, it only highlights certain ores, and these ores remain the only ones that are highlighted every time the signal is activated. How can I fix this?

Roblox has a limit of 31 active highlights for performance reasons. You can get the distance between the player and the orb, and if it’s in within anywhere from 50 to 150 studs (I don’t recommend any lower or higher than that range), then you highlight the orb to help get around this.

In the game I’m currently working on, I have “spy glasses” that highlight enemies. I use a magnitude check on every enemy to see if their in a certain distance, and using RenderStepped, will unhighlight them if they’re out of range.

Remember to delete old highlights instead of just make them invisible. They will still be active, just not visible, which will limit even further the amount of highlights you’ll be able to see.

2 Likes

Thank you, I thought this was the issue at the start since there are about 200 ores ingame at a time :skull:

1 Like

The 31 highlight limit kinda sucks and it’s a pain to get around, but magnitude checks are very simple; just annoying extra steps. However, it is understandable, because the way they work would cause extreme lag with anymore than like 35 or 40 active at a time on good hardware.

1 Like

Thanks, this works very well with RenderStepped.

There’s a really easy solution for this, just put all of your parts in a model, and put a highlight in that model. That highlight will render for every part inside that model, therefore allowing you to “bypass” the limit. No need for RunService.

Code:

local colors = {
	common = Color3.fromRGB(255, 255, 255),
	rare = Color3.fromRGB(0, 0, 255),
	epic = Color3.fromRGB(170, 0, 255),
	legendary = Color3.fromRGB(255, 170, 0),
	mythical = Color3.fromRGB(255, 0, 70),
	exotic = Color3.fromRGB(255, 255, 0),
	ethereal = Color3.fromRGB(0, 255, 255),
	celestial = Color3.fromRGB(25, 0, 100),
}

game.ReplicatedStorage.Events.HighlightOres.OnClientEvent:Connect(function()
	if canSpelunk then
		script.Parent.Highlights:ClearAllChildren()
		canSpelunk = false
		script.activate.PlaybackSpeed = math.random(5,15)/10
		script.activate:Play()
		
		local oreHolders = {}
		
		for name, color in pairs(colors) do
			local newModel = Instance.new("Model")
			newModel.Parent = workspace.possibleOreSpots
			
			local h = script.Highlight:Clone()
			h.Name = name
			h.Adornee = newModel
			h.FillColor = color
			h.OutlineColor = color
			h.Parent = script.Parent.Highlights
			
			oreHolders[name] = newModel
		end
		
		for i,ore in pairs(workspace.possibleOreSpots:GetDescendants()) do
			if ore:FindFirstChild("isOre") then
				local rarity = ore.rarityForSpelunkers.Value
				ore.Parent = oreHolders[rarity]
			end
		end
	end
	
	task.wait(15)
	
	for i,h in pairs(script.Parent.Highlights:GetChildren()) do
		if h:IsA("Highlight") then
			game.TweenService:Create(h,TweenInfo.new(15,Enum.EasingStyle.Quint,Enum.EasingDirection.In),{FillTransparency = 1, OutlineTransparency = 1}):Play()
		end
	end
	
	task.wait(15)
	canSpelunk = true
end)

You will need to tweak this script to fit your game, but after tweaking, it should work. More on the highlight bypass if needed: Multiple Highlights not working - #4 by okayendo

1 Like

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