repstorage.RoundTag.Changed:connect(function(value) if value == true then print("1") if repstorage.GameRound.Value == "Deathmatch" then print("2") for _, player in pairs(game.Players:GetPlayers()) do print("3") player.CharacterAdded:connect(function(character) print("4") character:WaitForChild("Humanoid").Died:connect(function() print("5") wait() if character.Humanoid:FindFirstChild("creator") then print("6") local tag = character.Humanoid.creator local plr = tag.Value local tColor = player.TeamColor local kColor = tag.Value.TeamColor if not kColor then return end if not tColor then return end 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 end end end)
Ok, so this works but, for it to work you must: Kill someone first, then kill them AGAIN to get the score + 1. How come it takes 2 deaths for the score to start working. I want so if you kill them it gives you a score straight away. Please help.
EDIT
Output 1 2 3 3 4 Prints 1 2 3 3 when game starts and 4 when the player dies
When you kill a player again then it prints 5 and 6
Figured out the problem!
What's happening here is you're waiting for the CharacterAdded
event to fire for Players that already have Characters!
Sorry that took so long.
To fix this, I'm making the CharacterAdded code a function, to avoid typing it twice, and doing this:
function listenForDeath(player) local character = player.Character character:WaitForChild("Humanoid").Died:connect(function() wait() if character.Humanoid:FindFirstChild("creator") then local tag = character.Humanoid.creator local plr = tag.Value local tColor = player.TeamColor local kColor = tag.Value.TeamColor if not kColor then return end if not tColor then return end 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 repstorage.RoundTag.Changed:connect(function(value) if value == true then if repstorage.GameRound.Value == "Deathmatch" then for _, player in pairs(game.Players:GetPlayers()) do player.CharacterAdded:connect(function(character) listenForDeath(player) end) if player.Character then listenForDeath(player) end end end end end)