Basically whenever a player dies I want it to immediately set their team to the white team.
place this in a char.
script.Parent.Humanoid.Died:Connect(function()
game.Players:FindFirstChild(script.Parent.Name).Team = game.Teams["yourdeathteam"]
end)
As server script
You can call the Humanoid.Died event to detect when players die and execute code. The code example on the DevHub reference page is good, however I have provided an example of how to do your particular request below.
-- Script in ServerScriptService
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
player.TeamColor = BrickColor.new("TeamColorHere")
-- or: player.Team = game.Teams["TeamNameHere"]
end)
end)
end)
Are you sure it wouldn’t break if multiple people join at the same time or die at the same time?
How would I place it in every character when they join?
Yes, as the connection in the code above is specific to each player. The game will execute the code inside the PlayerAdded function for every player who joins the game individually.
Oh, well it didn’t work----------
Did you replace “TeamColorHere” with the TeamColor name?
Oh nvm i found out what I did wrong. Thank you!
I believe assigning the “Team” property of the player instance with a team instance would be more efficient here as you would circumvent the need to create a new BrickColor value each time the player’s character dies. This is relatively simple, at the top of your script create a reference to the teams service.
local teams = game:GetService("Teams")
Then when the team change is performed, instead of assigning to the “TeamColor” property of the player you can instead do.
player.Team = teams.Red
Put in in StarterPlayer - startercharacterscripts