✓ Accepted answer
Notice how you put the function in the game.Players.PlayerAdded and the Player.CharacterAdded... Well, just know that these will not always run, so what I would do is create a Script in StarterPack. The reason why I would do this is because you can't always define the player in Scripts that are not a descendant or a parent of the player. So in this script in StarterPack, try doing this:
local player = script.Parent.Parent
repeat wait() until player.Character ~= nil
local character = player.Character
local humanoid = character.Humanoid
humanoid.Died:connect(function()
if player.TeamColor = BrickColor.new('Bright red') then
print('A player has died!')
end
end
So, first we define the player. This has to be script.Parent.Parent, since the script is going to be inserted into Backpack, and Backpack is the parent of the script, and then the Player is the parent of the Backpack.
Then we wait until the character exists. Better to be safe than sorry!
Then we define more variables.
Next, we make the humanoid.Died function. Then we check if the player is in the same team, and if it is, then it will print when they die.
I hope this helped!
5 comments
If you are testing this offline then your player is created before scripts run, so PlayerAdded and CharacterAdded are never fired.
I am trying this online.
You're code is hard to read, please tab correctly. =)
Try adding print(Player.TeamColor) before line 3.
@ NathanTheDeveloper I apologize, I think you or someone else once told me before I should be tabbing more. I usually do it at the end to make it look neat, I just completely forgot to do it here. @ 1waffle1 I will try that and see if the script is running correctly