what i meant here is, how when the game starts it will clone the map from replicatedstorage, the thing im confused is how do i check when 2 players joined, then the map loads, i dont know about the check amount of player thing
Cancel auto loading character in studio. Give the player a GUI with a Start Game button. When player clicks the button, LoadCharacter(), and add the player into a table.
If the table is >= 2, clone the map from ServerStorage and place it in game.
When player leaves, remove it from table, make sure to use a debounce so it doesnt clone the map twice
Checks how many players are in-game before continuing further code:
local players = game:GetService("Players")
while task.wait() do
if #players:GetPlayers() >= 2 then
print("Enough players!")
-- A certain action will fire here once this condition was met
else
print("Not enough")
end
end
Honestly I dont see why having an infinite loop just for checking that, you could do it on PlayerAdded event, instead of a loop
Ok.
local Players = game:GetService("Players")
repeat Players.PlayerAdded:Wait() until #Players:GetPlayers() >= 2
But that will only run until players are 2, and it will never listen again, but yeah does the trick
That’s why I use while loops cause it always checks.
You could do something like this?
local Players = game:GetService("Players")
while #Players:GetPlayers() < 2 do
Players.PlayerAdded:Wait()
else
print("There are enough players to start the game")
end
The methods you suggested works, Im not saying the opposite.
I just meant, that its possible to do it without any loop, by just listening PlayerAdded event, and check if to start game or not. It would constantly checking too, but without a loop, just event based
game.Players.PlayerAdded:Connect(function()
if #game.Players:GetPlayers() >= 2 then
end
end)
this also a good solution, thanks
i havent test this but i trhink it works
ill replace button with a gui load screen, also works right’?
Sure, if at the end of the loading you call the StartGame function or giving a Play button to the player after the loading screen ended
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.