while true do if game.Players.LocalPlayer.Character.Humanoid.Health == 0 then game.Players.LocalPlayer.TeamColor = game.Teams["Dead"].TeamColor end wait() end
This is supposed to switch someone to team "Dead" when the game detects their health to be 0. It doesn't work. It's in a local script as well, someone help?
Your script is inefficient constantly checking if the player's health is 0. This is unnecessary and if you have too many repeating loops, you might end up lagging your game.
You can actually use the Died
event of Humanoid. This script really should be put in a server script as it deals with the changing of teams.
With the died event, we want to establish PlayerAdded and CharacterAdded events as well.
game.Players.PlayerAdded:connect(function(Player) --Player is the person who just joined the game, we can use the Player instance to help detect if a new Character was created. Player.CharacterAdded:connect(function(Character) --At this point the player has respawned and now we can access the Character through the Character variable. Character:WaitForChild('Humanoid').Died:connect(function() --At this point the player's character has died, now we can change the player's TeamColor. For this we can use the Player variable we established in the first function. Player.TeamColor = game.Teams.Dead.TeamColor end) end) end)