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 8 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 — 8y

2 answers

Log in to vote
1
Answered by 8 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.

01function onUpdate()
02local t1 = 0
03local t2 = 0
04for i,v in pairs(game.Players:GetChildren()) do
05    if v.Team == game.Teams.x then --x = Team name
06        t1 = t1 + v.leaderstats.Points.Value
07    elseif v.Team == game.Teams.x2 then --x2 = Team name
08        t2 = t2 + v.leaderstats.Points.Value
09    end
10end
11if t1 == max then
12    --code for winning
13elseif t2 == max then
14    --code for winning
15elseif t1 == max and t2 == max then
View all 23 lines...

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

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

1local plrs = game.Teams.RedTeam:GetPlayers()
2 
3for i, plr in ipairs(plrs) do
4    plr.leaderstats.terrain.Value = plr.leaderstats.terrain.Value + 1
5end
0
Thank You so much! Pidude_314 -5 — 8y
0
wait... i'm starting this think this isn't what you meant Perci1 4988 — 8y

Answer this question