for _, player in pairs(game.Players:GetPlayers()) do coroutine.resume(coroutine.create(function() player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid") print("4") character.Humanoid.Died:wait() print("4.5") if character.Humanoid:FindFirstChild("creator") then print("5") local tag = character.Humanoid.creator local tColor = player.TeamColor local kColor = tag.Value.TeamColor if not kColor then return end if not tColor then return end print("6") if tColor ~= kColor then if kColor == BrickColor.new("Lime green") then greenscore.Value = greenscore.Value + 1 elseif kColor == BrickColor.new("New Yeller") then yellowscore.Value = yellowscore.Value + 1 end end end end) end)) end
When a player dies and is added back to the workspace it prints 4 but it does print 5 after it trys to find creator. Please help. Im just want this script to check when a player dies and give the team who killed the player a point, like paintball or something i guess
EDIT I editted your answer, so I didnt get the error. You forgot to add.Humanoid after character on line 5. I added that but then it just printed 4 no error, just a bunch of 4's in the server output
Your script doesn't check for creator when the player dies, it checks for the creator value when they respawn. You would want to use the Humanoid Died Event for the script to look for creator when the player dies.
for _, player in pairs(game.Players:GetPlayers()) do coroutine.resume(coroutine.create(function() --I just added this because I was concerned the script would pause until the first player died. The coroutine is kind of like a separate script. player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid") print("4") character.Died:wait() --A trick I learned, it will keep the event in wait until the player dies. if character.Humanoid:FindFirstChild("creator") then print("5") local tag = character.Humanoid.creator local tColor = player.TeamColor local kColor = tag.Value.TeamColor if not kColor then return end if not tColor then return end print("6") if tColor ~= kColor then if kColor == BrickColor.new("Lime green") then greenscore.Value = greenscore.Value + 1 elseif kColor == BrickColor.new("New Yeller") then yellowscore.Value = yellowscore.Value + 1 end end end end) end)) --End of the coroutine. end