I want to make it so it checks if there are 2 or more players in 1 game and if there is then it will start it
I have tried writing my own script for it but it doesnt work and it doesnt show any errors in the output
Try using this as an example, this is pretty much what you wanted.
Hope I helped!
use
if #game.Players:GetChildren() >= 2 then
----do thing
This will not work btw, as you’re comparing a number value to a Table of players.
Just want to point this out.
That’s my bad, no need for being angry as its a simple mistake.
On my end, I used your script with a print, and nothing was printed.
The actual method is game:Get service("Players"):GetPlayers()
as best practice. Use the #
operator to find out the number of them.
When on the server, you don’t have to use GetService on the players service, since the Players service is always present. But indeed you should use it on other services like Teams, TweenService ect.
But you’re right on the GetPlayers part.
I tried that and it didnt work
local PlayerCount = game.Players:GetChildren()
if PlayerCount >= 2 then
--teliport or whatever you want done
Thats how I would do it
use this
local Plrcount = game.Players:GetChildren()
if #Plrcount >= 2 then
--Whatever you want
else
print(2 - #Plrcount.." more Player(s) needed to start.")
end
s
end
I expect it to start the game if there are at least 2 players
You need to check the number of players in a loop.
You can do this by adding an event listener to the PlayerAdded
event to check if the number of players is 2 or more.
if #game.Players:GetPlayers() >= 2 then
-- do things
end
end)
What does > mean?
if #game.Players:GetPlayers() >= 2 then
-- do things
end
end)