|
So I'm creating a game, and I've never used NumPlayers before and I'm having it so if theres two or more players it would do something, but if theres under two players then it wouldn't do anything until two players.. but it's not working
But how would I make it so it repeats it so it doesn't only work once, because when I test it in studio and I add one player, it prints "not enough players" but when I add another player it doesn't print "starting game"
if game.Players.NumPlayers == 2 then
print('starting game')
else
print('not enough players')
end
|
|
LuaCymruJoin Date: 2015-01-22 Post Count: 394 |
if #game.Players:GetChildren() >= 2 then
print('starting game')
else
print('not enough players')
end |
|
LuaCymruJoin Date: 2015-01-22 Post Count: 394 |
To make it repeat, just enable and disable the script? depends on how the game works |
|
AliicsJoin Date: 2014-09-29 Post Count: 471 |
game.Players.PlayerAdded:connect(function(player))
-- Check for if there enough players
end)
-- You might also want to check for the amount of players on PlayerRemoving / PlayerRemoved |
|
|
Use the playeradded function and you also have a error use >=2 rather than ==, otherwise it will only run if there is 2 players no more or no less. |
|
|
number = 0
function count()
for i,v in pairs(game.Players:GetPlayers()) do
number = i
print(number.. " Online")
end
if number >= 2 then
print("There are enough players")
elseif number < 2 then
print("Not Enough Players!")
end
end
game.Players.PlayerAdded:Connect(count)
game.Players.PlayerRemoving:Connect(count)
This script will count the number of players everytime someone joins or leaves and after it finishes counting if there are 2 or more players it will print that theres enough players if not it will say not enough players replace whats inide the if statements with what you want it to do |
|
Savi_oooJoin Date: 2012-06-10 Post Count: 214 |
local Players = game:GetService('Players')
local function Check()
if #Players:GetPlayers() >= 2 then
return true
end
return false
end
while wait() do
if Check() then
print('Starting Game')
else
warn('Insufficient Players')
end
end
~ 𝓢𝖆𝖛𝖎 |
|
TNTeonJoin Date: 2017-07-31 Post Count: 5 |
can someone help me, I am getting this error that says
ServerScriptService.MainScript:69: 'do' expected near '='
this is my code
for i = 60,0,-1 and KingTouch = false do
I know it has a problem with my = sign but i don't know why, please help me! |
|
TNTeonJoin Date: 2017-07-31 Post Count: 5 |
by the way the answer to your problem is
while game.Players.NumPlayers < 2 do
print('There needs to be 4 or more players to begin')
repeat wait(2) until game.Players.NumPlayers >= 2
end
print('starting game') |
|
TNTeonJoin Date: 2017-07-31 Post Count: 5 |
sorry it should be
while game.Players.NumPlayers < 2 do
print('There needs to be 2 or more players to begin')
repeat wait(2) until game.Players.NumPlayers >= 2
end
print('starting game') |
|
imaski4Join Date: 2015-11-29 Post Count: 7 |
TNTeon you have to use == false ok |
|
TNTeonJoin Date: 2017-07-31 Post Count: 5 |
now it says
ServerScriptService.MainScript:69: 'for' step must be a number |
|
|
TNTeon the KingTouch = false should be in an if statement and include the for statement in it |
|
TNTeonJoin Date: 2017-07-31 Post Count: 5 |
I want it to stop changing i too and move on to the following script |
|