local NumPlayers = #game.Players:GetPlayers(); if NumPlayers > 1 then --- script here else print("Not enough players") end
This part of the script is basically made to not let the rest of the script run unless there's more than 1 player in the game. However, no matter what it always just says that there's not enough players, even with 2 players in the game. Help?
What it looks like to me is that your running the function once, immediately when the first player joins. Assuming your doing this, that's your problem. The script runs before/while the second player connects. What you'll need to do is call the function when a new player joins, perhaps like this?
game.Players.OnPlayerAdded:connect(function(player) local NumPlayers = #game.Players:GetPlayers(); if NumPlayers > 1 then --- script here else print("Not enough players") end end)
Of course, that just a suggestion, you should do it however you see fit.
Also, notice how I define the number of players in the 'OnPlayerAdded' function, and not outside of it. This way, the game can check the number of players each time a new one joins. Of course, it wont run/check how many there are if a player leaves, but you can fix that if need be. Hope this helps! :)
local NumPlayers = #game.Players:GetPlayers(); if NumPlayers > 1 then --- script here else print("Not enough players") end
That's some mean problem that I ran into several times already too. This only checks ONCE if there are enough players. It is supposed to check until the needed amount is reached. So just do it like that:
local NumPlayers = #game.Players:GetPlayers(); repeat if NumPlayers > 1 then -- script here else print("Not enough players") end wait() until NumPlayers > 1
repeat wait() until
is a kind of loop that is supposed to happen until something has happened. Now if it's about the variable itself, you may also try a few other methods. Like table.getn()
or even a for
loop. table.getn()
gets the length of a table, so you could do it like that:
local NumPlayers = table.getn(game.Players:GetPlayers()) repeat if NumPlayers > 1 then -- script here else print("Not enough players") end wait() until NumPlayers > 1
Hope this helps!