Title - I just want to make this script more reliable. In its current state, it doesn’t track when a players team is updated like I wanted it to. There are no errors in the console and it does track the amount of players when a user first joins, but afterwards it stops counting. I’ve tried fiddling with it, adding the “while do” loop and a few waits, but I can’t exactly figure out what I’m doing wrong.
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local status = RS:WaitForChild("Status")
roundTime = 50
inter = 15
canStart = false
roundStarted = false
requiredPlayers = 2
local function roundStart()
roundStarted = true
wait(inter)
local activePlayers = {}
status.Value = "Game starting shortly!"
for _, p in pairs (players:GetPlayers()) do
if p.Team == "Ready" then
activePlayers.Insert(p)
p.Team = "In-Game"
end
end
-- blah blah blah, extra round code here lol
end
if canStart == false and roundStarted == false then
while canStart == false and roundStarted == false do
local plrs = players:GetPlayers()
if #plrs >= requiredPlayers then
local activePlayers = {}
for _, p in pairs (players:GetPlayers()) do
if p.Team == "Ready" then
activePlayers.Insert(p)
end
if #activePlayers >= requiredPlayers then
canStart = true
roundStart()
else
canStart = false
roundStarted = false
wait(1)
status.Value = "Needs at least "..requiredPlayers - #activePlayers.." more player[s]."
end
end
else
canStart = false
roundStarted = false
local activePlayers = {}
for _, p in pairs (players:GetPlayers()) do
if p.Team == "Ready" then
activePlayers.Insert(p)
end
end
wait(1)
status.Value = "Needs at least "..requiredPlayers - #activePlayers.." more player[s]."
end
end
end
Do go easy on me heh, I’m not extremely familiar with coding and can really only do the most bare-bones functions.