Script is only working for one player

Hello! I’m working on a sort of ESP system, where in one player in the game is chosen and every other player in the game is highlighted.

The script works fine, but only for 1 player. So it’s only highlighting one player thats in the game rather than all of the players in the game

I’ve looked for solutions on the developer hub, but couldn’t find anything similar to what I’m doing. I’m looking at my script and maybe because it’s 2AM but I can’t seem to snoop out what the issue may be. It’s a relatively simple script, which shouldn’t make it hard to find the issue.

game.ReplicatedStorage:WaitForChild("Remotes").Highlight.OnClientEvent:Connect(function()
	for i,v in pairs(game.Players:GetChildren()) do
		local char = v.Character or v.CharacterAdded:Wait()
		
		local r = math.random(0,255)
		local g = math.random(0,255)
		local b = math.random(0,255)
		
		for i,v in pairs(char:GetDescendants()) do
			if v:IsA("BasePart") then
				local Highlight = Instance.new("Highlight",v)
				Highlight.FillTransparency = 1
				Highlight.OutlineColor = Color3.fromRGB(r,g,b)
			end
		end
	end
end)

All help is appreciated!
Thanks in advance!

1 Like

Maybe its because theres a limit on how many highlights you can use, parent the Highlights to the Character not the BaseParts

1 Like

Good idea, I’m pretty sure there is a limit on the amount of highlights you can have at once for performance reasons. I completely overlooked that I can just parent it to the character instead of the base parts.

Thanks it all works now! I guess I’m too tired to do anything right now lol

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