Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script not getting NumPlayers right? [UNSOLVED]

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

Try if game.Players.NumPlayers > 1 then

2 comments

0

But the person wants the condition to be game.Players.NumPlayers >=2

0

It doesn't work anyways

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

3 comments

0

still no success

0

how are you testing this? did you get a error message?if so,what is it?

0

There wasn't one.

This discussion is preserved as it was. New answers, comments, and votes are closed.