If I have 2 teams, and each team has players with some amount of kills. How would I get the sum of kills each team has?
I have tried giving every player a script that adds 1 to the result when they kill someone, but that did not seem to work, and the output was empty.
I think there must be a nice way of doing this, but I am more of a builder than a scripter, so I don’t know how I would do that. Any help is appreciated. Thanks!
You would want to track each players kill, perhaps make a NumberValue named ‘Kills’ in each player, and increment it in your server auth code for when the player kills someone.
Then to get the sum of each teams kills you would do
local Sums = {}
for _,p in ipairs(game.Players:GetPlayers()) do
if p.Team ~= nil and p:FindFirstChild("Kills") then
if Sums[p.Team.Name] == nil then Sums[p.Team.Name] = 0 end
Sums[p.Team.Name] = Sums[p.Team.Name] + p.Kills.Value
end
end
--[[
To get a teams kills you would index it in the table 'Sums'
so if you have a team named 'Snipers' and you want to get their total kills
you would run the above code and the total kills for that team would be located in Sums["Snipers"]
]]
6 Likes