Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you select the total kill value of the team in the leaderboard?

Asked by 4 years ago

Basically what I want to do is Make a gui that shows the total kills of both teams, however I am having trouble of trying to select the team's total kills... I really have no idea what should I do first since I am not that professional in scripting yet so I just wanna know how do you make a script to get the total kills of a team.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

im guessing you request for something like this

remember to change the teams in if (p[i].TeamColor == game.Teams:FindFirstChild("blue").TeamColor) then and if (p[i].TeamColor == game.Teams:FindFirstChild("red").TeamColor) then

function getWinningTeamString()
    local red = 0
    local blue = 0

    local p = game.Players:children()
    for i=1,#p do
        if (p[i].TeamColor == game.Teams:FindFirstChild("blue").TeamColor) then
            if (p[i]:FindFirstChild("leaderstats") ~= nil and p[i].leaderstats:FindFirstChild("Kills") ~= nil) then
                blue = blue + p[i].leaderstats:FindFirstChild("Kills").Value
            end
        end

        if (p[i].TeamColor == game.Teams:FindFirstChild("red").TeamColor) then
            if (p[i]:FindFirstChild("leaderstats") ~= nil and p[i].leaderstats:FindFirstChild("Kills")~= nil) then
                red = red + p[i].leaderstats:FindFirstChild("Kills").Value
            end
        end
    end
end

then just update it everytime something changes

edit: sorry for using anything thats deprecated but i dont got the time to fix those

Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited 4 years ago

Hello! I have made a function that gets the wins and returns a value

funtion GetTeamKills(TeamColor)
    local Kills = 0
    for i,player in pairs(game.Player:GetPlayers()) do
        if player.TeamColor == BrickColor.new(TeamColor) then
            local Stat = player.leaderstats:FindFirstChild("Kills")
            if Stat then
                Kills = Kills + Stat.Value
            end
        end
    end
    return Kills
end
local Kills = GetTeamKills("Really Red")--Kills will be the value of the teams kills

Change the value Really Red to your team color. No need for the BrickColor.new thingy You can copy and use this all you want!

If you have any questions, comment below!

Best,

TheLastHabanero

Answer this question