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

How can I add wins to the winner's leaderstats?

Asked by 4 years ago

I need to add wins to people who are on a specific team if it meets specific requirements. If there is more than 0 people on a team at the end of the timer then everyone on that team will get one win. I did not receive any error messages.

local teams = game:GetService("Teams"):GetTeams()
while wait(1) do
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")

 if team.Name == "Hiding" and #players > 0 then
    if game.Workspace.GameActive.Value == true then
    local players = game:GetService("Players")
for i,v in pairs(players:GetPlayers()) do
    if v.TeamColor == BrickColor("Cyan") then
        v.leaderstats.Wins.Value = v.leadersats.Wins.Value + 1
    end
end

end
        end
    end
end

The original script I had worked so I believe the mistake is when I used for i, v in pairs(Players:GetPlayers()) do. This was my original script that did work.

local teams = game:GetService("Teams"):GetTeams()
while wait(1) do
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")

 if team.Name == "Hiding" and #players > 0 then
    if game.Workspace.GameActive.Value == true then
        game.workspace.HidingWinTestA.Value = true
    end
end
end
        end
    end
end
0
The second argument in the in pairs loop cannot be the same as a variable. PrismaticFruits 842 — 4y

Answer this question