Hello! I was making a global timer that sets off other events and I didn't get very far before seeing an error that didn't pop up in the output. Off the bat I know there are probably many errors in this, but one thing that stands out is the game can't tell how many players are in the game. It just keeps doing the loop and printing (Not enough players). I tested this on a server with 3 people, but it still doesn't work.
Here's the script:
--Timers local r = 25 --Before match local g = 420 --During Match local b = 600 --During Boss local c = 15 --Waiting for players local t local team = game.Teams.Fighting:GetChildren() local teamc = #team --Variables local players = game.Players:GetPlayers() --Code Start local function init () t = tick() end while true do print("Intermission") wait(r) if #players >= 2 then print("Match Started") repeat local curt = tick() local match = t - curt until match > g or teamc == 1 print("Match Ended") else if #players < 2 then print("Not Enough Players") end end end
Thanks for looking!
The problem is you're setting the number of players upon the server's creation and then never changing it in the loop. So when the first player joins, #players will always remain 1 forever because it isn't being updated. To fix this, simply include it in the loop. To help you out, I'm also going to take out the obsolete stuff, but feel free to add it back if desired.
--// Settings //-- local r = 25; --Before match local g = 420; --During Match local b = 600; --During Boss local c = 15; --Waiting for players --// Main Loop //-- while true do local team = game.Teams.Fighting:GetChildren(); local teamc = #team; local players = game.Players:GetPlayers(); local t = tick(); while #players < c do players = game.Players:GetPlayers(); wait(); end print("Intermission"); wait(r); local curt = t; local match = t - curt; --// I don't know what the purpose of this is. Will return either nil or 0 until match > g or teamc == 1 print("Match Ended") end end end
You are getting the amount of players only once, when the script first runs. So players will always be a table of one value - the first player who joined the server.
You need to GetPlayers() at the start of every loop:
--Timers local r = 25 --Before match local g = 420 --During Match local b = 600 --During Boss local c = 15 --Waiting for players local t local team = game.Teams.Fighting:GetChildren() local teamc = #team --Code Start local function init () t = tick() end while true do print("Intermission") wait(r) local players = game.Players:GetPlayers() if #players >= 2 then print("Match Started") repeat local curt = tick() local match = t - curt until match > g or teamc == 1 print("Match Ended") else if #players < 2 then print("Not Enough Players") end end end