So im trying to do a Queue thing. When you join the game there is a button called "PLAY" and i want that if u click it , it will add you to the _G.gameplayers {} table .
my Main script now should do the thing that it first checks before everything starts that atleast 1 player is in the _G.gameplayers {} table. If not it says " not enough Players ". My Error code is :
ServerScriptService.MAIN:14: attempt to compare number with nil
Here is my Click script where u need to click to be added to the table :
function join() wait() _G.gameplayers = {} local human = game.Players:FindFirstChild("Humanoid") if human then table.insert(_G.gameplayers, human.Name) end end script.Parent.MouseButton1Down:connect(join)
And here is the Main script where my Roundgame is
local replicatedstorage = game:GetService("ReplicatedStorage") local status = replicatedstorage:WaitForChild("InfoValue") local mapstorage = game.workspace:WaitForChild("mapStorage") RoundLive = false --Falls jemand geld kriegt --game.Players.leaderstats.Wins.Value = game.Players.leaderstats.Wins.Value + 1 while true do _G.gameplayers = {} if _G.gameplayers.NumPlayers == nil then status.Value = "not enough players" repeat wait(1) until _G.gameplayers.NumPlayers >- 2 end end wait(1) for i = 10,0,-1 do status.Value = "Preparing game in "..i wait(1) if i == 0 then status.Value = " " end end --_G.gameplayers = {} --for i, v in pairs(game.Players:GetPlayers()) do --if v then -- table.insert(_G.gameplayers, v.Name) --end --end status.Value = "A new game is starting now." wait(2) status.Value = "Get ready to play!" wait(3) --Die Map wird in Workspace reinkopiert local mapsinserverstorage = game:GetService("ServerStorage").Maps:GetChildren() local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)] chosenmap:Clone().Parent = mapstorage local spawns = chosenmap:WaitForChild("Spawns"):GetChildren() for _,Player in pairs(game.Players:GetPlayers(_G.gameplayers)) do if Player and #spawns > 0 then local torso = Player.Character:WaitForChild("Torso") local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and torso then table.remove(spawns, allspawns) --Teleportiere die Spieler in das Spiel torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0)) --Teleportiere den Gegner AI in die Map local enemie = game.ReplicatedStorage:FindFirstChild("Enemies"):GetChildren() GegnerStorage = game.workspace:WaitForChild("GegnerStorage") for _,obj in pairs(enemie) do obj:Clone().Parent = GegnerStorage end --Waffen werden hinzugefĆ¼gt --local M4AR = game.ReplicatedStorage.M4AR --local newM4 = M4AR:Clone() --newM4.Parent = Player.Backpack end end end for i = 60,0,-1 do wait(1) --Wenn die Zeit abgelaufen ist if i == 0 then status.Value = "You Lost there was no Time left!" wait(2) break end --Die Gegner haben gewonnen da keine Spieler mehr am Leben sind if #_G.gameplayers == 0 then status.Value = "You Lost" wait(2) break end if #GegnerStorage:GetChildren() == 0 then status.Value = "You Won" wait(2) break else status.Value = i.." seconds remaining" end end local spawns = game.Workspace.Lobby:WaitForChild("Spawns"):GetChildren() for _,Player in pairs(game.Players:GetPlayers()) do if Player and #spawns > 0 then local torso = Player.Character:WaitForChild("Torso") local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and torso then table.remove(spawns, allspawns) torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0)) Player.Backpack:ClearAllChildren() status.Value = " " end end end --Entfernt alle Tools am ende jeder Runde --leert die Map aus Mapstorage und die Gegnerstorage komplett mapstorage:ClearAllChildren{} GegnerStorage:ClearAllChildren{} wait(5) for v, Player in pairs(game.Players:GetPlayers()) do v.Backpack:ClearAllChildren() v.Health = 100 wait() end
please ignore my german langue there . it doesnt affect the script :)) Thanks guys