How do i make a game start thingy

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

1 Like

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

1 Like

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
1 Like

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
1 Like

But that will only run until players are 2, and it will never listen again, but yeah does the trick :stuck_out_tongue_winking_eye:

1 Like

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
3 Likes

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

1 Like
game.Players.PlayerAdded:Connect(function()
	if #game.Players:GetPlayers() >= 2 then
		
	end
end)
2 Likes

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.