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

I know how to check a player's leaderstats, but how do you do the same for a team?

Asked by 7 years ago

I am currently scripting a game where teams receive points from stepping on bricks, but need the round to stop when a certain team has that many points. I am using leaderstats with the name "terrain"

0
Every time you give someone points, give points to their team-points variable as well. Otherwise you have to constantly loop through players. cabbler 1942 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago

There are multiple ways to go about doing this and all of them are the right way, but I'm gonna do this my way.

function onUpdate()
local t1 = 0
local t2 = 0
for i,v in pairs(game.Players:GetChildren()) do
    if v.Team == game.Teams.x then --x = Team name
        t1 = t1 + v.leaderstats.Points.Value
    elseif v.Team == game.Teams.x2 then --x2 = Team name
        t2 = t2 + v.leaderstats.Points.Value
    end
end
if t1 == max then
    --code for winning
elseif t2 == max then
    --code for winning
elseif t1 == max and t2 == max then
    --code for draw or just delete if you don't want a draw to happen
end
end

while true do
    onUpdate()
    wait(0.2)
end

I haven't tested this code, so tell me if it works or not.

0
Thanks, it works great! Pidude_314 -5 — 7y
0
No problem Meltdown81 309 — 7y
Ad
Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Use GetPlayers() to get a list of all the players on a team. Then all you have to do is loop through the list and change the leaderstats:

local plrs = game.Teams.RedTeam:GetPlayers()

for i, plr in ipairs(plrs) do
    plr.leaderstats.terrain.Value = plr.leaderstats.terrain.Value + 1
end
0
Thank You so much! Pidude_314 -5 — 7y
0
wait... i'm starting this think this isn't what you meant Perci1 4988 — 7y

Answer this question