Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not getting NumPlayers right? [UNSOLVED]

Asked by 8 years ago

My error is at line 8. When I change it to 1, it works. If I change it to 2, then it doesn't work. Please help.

gameTime = 15 --Edit to time game.  
gameRunning = false
gameReady = false   
timer = game.workspace:WaitForChild("Timer") 

--------------------------------------------------------------------------------------------------------------------------------------
while wait() do
if game.Players.NumPlayers >= 2 then
    gameReady = true
    break
else
    timer.Value = "There needs to be 2 or more Players for Towergames to start."
    gameReady = false
    end
end

    function runGame1()
            gameRunning = true
            _G.runTime()
            local map = game.ReplicatedStorage.GameItems.Maps:findFirstChild("Sword Arena"):Clone()
            map.Parent = game.workspace
            timer.Value = "The Minigame is Sword Fighting"
            wait(2)
            timer.Value = "Get Ready..."
            wait(2)
            timer.Value = "Go!!"
            wait(.1)
            local player = game.Players:GetChildren()
            for i = 1, #player do
                local character = player[i].Character
                player[i].leaderstats.InGame.Value = 1
                game.ReplicatedStorage.GameItems.Tools:findFirstChild("Sword"):Clone().Parent = player[i].Backpack
            local spawns = map.Spawns:GetChildren()                     
            local randomSpawn = spawns[math.random(#spawns)]
            if character then
                character:MoveTo(randomSpawn.Position)   
            character.Humanoid.Died:connect(function()
                local pplay = game.Players:WaitForChild(character.Name)
                local inGamey = pplay:WaitForChild("leaderstats").InGame
                inGamey.Value = false
end)    
            wait(gameTime)
            local player1 = game.Players:GetChildren()
            for i = 1, #player1 do
                if player1[i].leaderstats.InGame.Value == 1 then
                    player1[i]:LoadCharacter()
                    game.Workspace:findFirstChild("Sword Arena"):remove()
                    timer.Value = "Game has ended."
                    player1[i].leaderstats.Points.Value = player1[i].leaderstats.Points.Value + 10
                    player1[i].leaderstats.InGame.Value = 0 
                    wait(2)
                end
            end
            wait(1)
            gameRunning = false
end 
            end
    end

while wait() do
    local minigame = math.random(1)
  if minigame == 1 and gameRunning == false and gameReady == true then 
    runGame1()      
end
end

EDIT: I now receive this error while testing a two person server: 17:15:16.108 - ServerScriptService.GameScript:19: attempt to call field 'runTime' (a nil value) 17:15:16.123 - Stack Begin 17:15:16.124 - Script 'ServerScriptService.GameScript', Line 19 - global runGame1 17:15:16.124 - Script 'ServerScriptService.GameScript', Line 63 17:15:16.125 - Stack End

2 answers

Log in to vote
0
Answered by 8 years ago

Try if game.Players.NumPlayers > 1 then

0
But the person wants the condition to be game.Players.NumPlayers >=2 bosswalrus 84 — 8y
0
It doesn't work anyways User#9949 0 — 8y
Ad
Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
8 years ago

08 if game.Players.NumPlayers >= 2 then

try 08 if (game.Players.NumPlayers) >= 2 then

if that fails to work you can get the number of players using this:

players=game.Players:GetPlayers()
numberofplayers=#players
0
still no success User#9949 0 — 8y
0
how are you testing this? did you get a error message?if so,what is it? lukeb50 631 — 8y
0
There wasn't one. NeonicPlasma 181 — 8y

Answer this question