PlayerAdded Function not working inside Local Script?

So I am making a Local Script Located in StarterGUI (Not in a ScreenGUI) that changes player parts color into their team color once they join.

They are colored when they join, problem is whenever someone is killed, the code doesn’t run anymore. Meaning color is back to default

Neither ‘PlayerAdded’ or ‘CharacterAdded’ prints. The only piece of code running is the last for loop, so the code only works once

function cellshade(Character)
end
function OnPlayerJoin(e: Player)
	cellshade(e.Character)
end

game.Players.PlayerAdded:Connect(function(player)
	print('Player Added !')

	player.CharacterAdded:Connect(function(char)
		print('Character Added !')
		for _, e in ipairs(game.Players:GetPlayers()) do 

			if e == game.Players.LocalPlayer then 
				continue 
			else 
				OnPlayerJoin(e)
			end
		end
	end)
	OnPlayerJoin(player)
end)


for _, e in ipairs(game.Players:GetPlayers()) do 
	if e == game.Players.LocalPlayer then 
		continue 
	else 
		OnPlayerJoin(e)
	end
end

1 Like

playeradded function AND characteradded function is for serversided sadly :slightly_frowning_face:

1 Like

Can’t you use them in Local Scripts ? I already did before tho.

Thats weird because that’s how I did my Team UI ?

then maybe
This event does not work as expected in solo mode – roblox devhub again ig

Oh wait it worked for player removing, from what i saw from devhub it says because the player is created before the script connects/player is created before the script is even created.
For team it was probably because they made sure the scripts loaded before you joined

PlayerAdded and CharacterAdded are server sided only! :slight_smile:

2 Likes

Then maybe making Server Client Remote Event ? I doubt its the most efficient way to do it.

Actually a server client remote event isnt a bad idea, ive done that a few times with character appearance loaded and playeradded. Give it a try and show me your code if you still need help with the server client remote event!

1 Like

Unintended behavior or someone needs to update the page. image

Therefore report worthy.

Why are you using PlayerAdded when you have LocalPlayer?

Because I want the local player to see other players in their team color

Then do it on the server.
Replicates to everyone.

Problem with doing it on the server is that Player A enemies is not same as Player B enemies.