what I would typically do is
repeat wait() until #game.Players:GetPlayers() >= 2
I used this sort of basic coding in one of my main projects a few years ago, managed to work just fine in servers with a runtime of 12+ hours.
what I would typically do is
repeat wait() until #game.Players:GetPlayers() >= 2
I used this sort of basic coding in one of my main projects a few years ago, managed to work just fine in servers with a runtime of 12+ hours.
Edited response, I think I should just make a new reply.
For Starters you can just wait until the Integer value of the collection of players from game.Players:GetPlayers().
while wait() do
if #game.Players:GetPlayers() >= 2 then
-- code here
end
There is also no reason for your to be saying:
if not ("SpawnPoint")then
print ("SpawnPoints not found!")
end
Proper way is to say if there is no spawnpoint in the map then it ends, we can achieve this by using this line of code
if not ClonedMap:WaitForChild("SpawnPoint") then
end
On top, we have the loop where we are waiting for the integer value of the children/collected bunch of players to be equal or greater than the least amount of players to play the round, which is 2.
Then at the next code block, we have the if statement of weather the map contains a spawnpoint or not. This is basically saying if the map does not have a spawn point in it, then it will end.
I would like to add onto this, you would also need to return rather than just printing “SpawnPoints not found!” otherwise the game would continue trying to run with no spawn points.
local Players = game:GetService"Players"
local function getnumplayers()
return #Players:GetPlayers()
end
while true do
Status.Value = “Waiting for enough players”
while getnumplayers() < 2 do wait(1) end
Would this work?
I just tried… Now the top says nothing.
I don’t mean to replace everything with that, you would set the Status as waiting for players and then begin the waiting
So it would look like this:
Status.Value = "Waiting for enough players"
repeat wait() until #game.Players:GetPlayers() >= 2
Wow, this helped… To get me to the next stage… Now it says “Cati chosen” (cati is one of my maps) . but it did not teleport me.
It also spawned the map into the map location.
What is the point of this loop exactly? It doesn’t do anything.
What… what is this doing? You know you can just not create an extra table, since ::GetPlayers
already returns a table.
The loop is looping the command to search for players, in order to start the game.
In your code you wrote:
This would not work, since the character does not exist outside of the scope. To correct this, try out this code:
for _,plr in ipairs(game.Players:GetPlayers()) do
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
plr.Character:SetPrimaryPartCFrame(AvailableSpawnPoints[1].CFrame)
table.remove(AvailableSpawnPoints,1)
end
end
Should I remove this from my code?
WaitForChild waits for it to exist if it doesn’t already. WaitForChild will always return something and will stall the code until there’s something with that name.
Yeah, it’s just pointless. If you want create an extra table, just do { unpack(Players:GetPlayers()) }
.
Would like to add on, You should use ‘FindFirstChild’ rather than ‘WaitForChild’
Please keep in mind new scripters may not know how they should correct this.
For it to teleport all the characters, you would have to loop through all the characters, but your players loop which checks if the character exists ends before the code which should run for every player, so it will error because of scope.
All that is happening with the code @xXVernandoXx is it is now saying said chosen map. But it is not teleporting me.
mind posting a .rbxl to help with debugging?
What do you mean… Sorry… To bug you.
.rbxl is a place file
It would be helpful if you posted one.