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"
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.
01 | function onUpdate() |
02 | local t 1 = 0 |
03 | local t 2 = 0 |
04 | for i,v in pairs (game.Players:GetChildren()) do |
05 | if v.Team = = game.Teams.x then --x = Team name |
06 | t 1 = t 1 + v.leaderstats.Points.Value |
07 | elseif v.Team = = game.Teams.x 2 then --x2 = Team name |
08 | t 2 = t 2 + v.leaderstats.Points.Value |
09 | end |
10 | end |
11 | if t 1 = = max then |
12 | --code for winning |
13 | elseif t 2 = = max then |
14 | --code for winning |
15 | elseif t 1 = = max and t 2 = = max then |
I haven't tested this code, so tell me if it works or not.
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:
1 | local plrs = game.Teams.RedTeam:GetPlayers() |
2 |
3 | for i, plr in ipairs (plrs) do |
4 | plr.leaderstats.terrain.Value = plr.leaderstats.terrain.Value + 1 |
5 | end |