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"
✓ ANSWER ACCEPTED
I know how to check a player's leaderstats, but how do you do the same for a team?
2 answers
✓ Accepted answer
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.
2 comments
0
Thanks, it works great!
0
No problem
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
2 comments
0
Thank You so much!
0
wait... i'm starting this think this isn't what you meant
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Every time you give someone points, give points to their team-points variable as well. Otherwise you have to constantly loop through players.