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.
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.
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