local gui = game.Workspace.Part.v.z local plrs = game.Players:GetPlayers() function Intermission() for i = 20, 0, -1 do gui.Text = "Intermission: 0:"..i if i <= 9 then gui.Text = "Intermission: 0:0"..i end wait(1) end end function ChooseDuelers_Teleport() gui.Text = "Now choosing dulers, (1 and 2)." local p1 = plrs[math.random(1, #plrs)] local p2 = plrs[math.random(1, #plrs)] repeat local p2 = plrs[math.random(1, #plrs)] until p2 ~= p1 gui.Text = p1.Name.. " and " ..p2.Name.. " have been chosen." end function Round() for i = 40, 0, -1 do gui.Text = "Round, please wait: 0:"..i if i <= 9 then gui.Text = "Round, please wait: 0:0"..i end wait(1) end end while true do if game.Players.NumPlayers > 1 then Intermission() ChooseDuelers_Teleport() Round() elseif game.Players.NumPlayers == 1 then gui.Text = "Waiting for 2 or more players." end wait() end
ERROR: ServerScriptService.Script:17: bad argument #2 to 'random' (interval is empty)
Your problem is that your plrs
variable is created and saved as soon as the script runs. A script in ServerScriptService will run as soon as the server starts, and at that point there won't be any players in the game! This means that the plrs
variable will always be an empty table, and your script will error.
To fix this, simply declare plrs
inside of all functions that you use it in.
Activate everything when there are 2 players or more in the game
Allow = false game:GetService('Players').PlayerAdded:connect(function() --When a player is added, the value will update if game:GetService('Players'):GetPlayers() > 1 then Allow = true else Allow = false end end) game:GetService('Players').PlayerRemoving:connect(function() -- Same goes for last function if game:GetService('Players'):GetPlayers() > 1 then Allow = true else Allow = false end end) function example() --This is an example for every function if not Allow then return end --Code end