blueKills = 0 redKills = 0 for _, player in pairs(game.Players:GetChildren()) do local kills = player:WaitForChild("GameFolder").Kills.Value if player.TeamColor == game.Teams.Red.TeamColor then redKills = redKills + kills redValue.Value = redKills elseif player.TeamColor == game.Teams.Blue.TeamColor then blueKills = blueKills + kills blueValue.Value = blueKills end end
Can anybody help with this deathmatch script. I have it set so whenever a player kills another player, it gives them a 'kill' Now this script checks for the amounts of kills each player on the team has and adds it to their score. However, if a player with say 4 kills leaves the game, it removes their 4 kills from the games points. How can I stop this from happening?
I'm assuming that you're calling this loop every few seconds or something? It would be smarter to connect it to an event. - I'm assuming you want your teams to have kill values equal to the sum of all the kills on your team, so your first code should be this:
for _, player in pairs(game.Players:GetChildren()) do local kills = player:WaitForChild("GameFolder").Kills -- You want the object, not the value, to connect it to an event kills.Changed:Connect(function() -- when their kills increase, add it to the team if player.TeamColor == game.Teams.Red.TeamColor then redValue.Value = redValue.Value + 1 elseif player.TeamColor == game.Teams.Blue.TeamColor then blueValue.Value = blueValue.Value + 1 end end) end
now, when they leave, you want to remove that:
game.Players.PlayerRemoving:Connect(function(player) local kills = player:WaitForChild("GameFolder").Kills.Value -- In this case, you want the value if player.TeamColor == game.Teams.Red.TeamColor then redValue.Value = redValue.Value - kills elseif player.TeamColor == game.Teams.Blue.TeamColor then blueValue.Value = blueValue.Value - kills end end)
I just made this here, so I may have made a spelling issue or the indentation might be off, but that's how you should be doing it. Hope I helped!