Waiting for players

I’m wondering how to make a script that Fires an event when HALF the total players have loaded in.

I haven’t found any thing that would work for me on Youtube, or the DevForum.
I also have no script to begin with since I don’t know where to start.

Any help is appreciated!

Check the PlayerAdded event, for every player add a number and when the number of players is what you need then go, or every second check the number of players in The server

2 Likes

This would work, but the issue for me is how to get Half the players in the server.

The players get teleported from a lobby into a private server, so the number would vary from 1 player, up to 16 players.

Check how many people will be teleported, then divide that, then add to a number and wait for it to be that number

The check with the for loop, the half of your server, when the players in the server reach what you need then do what you be, like:

Players.PlayerAdded do
if Players:GetPlayers() = Players.MaxPlayers / 2 then
—other code

Not sure if it’s gonna work I Made it on my phone so, it should check every time a player is added if the number of players is the max server size divided by 2, and then run the other code

1 Like

Isn’t the MaxPlayers the total players possible in the server? Not the actual amount of players?

I might be wrong though…

I just worked it out myself, thank you to you guys who helped me though!

Here is my script for any who has the same problem:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function()
	
	local TotalPlayers = #Players:GetPlayers()

	local HalfPlayers = TotalPlayers * 0.5
	local RoundedPlayers = math.round(HalfPlayers) -- In case of Decimals, and Single Player

	print(HalfPlayers.." Is Half of the Players")
	print(RoundedPlayers.." Is Half of the Players, Rounded")

	print(TotalPlayers.." Is all the Players: Before Repeat")

	repeat
		Players.PlayerAdded:Wait()
		print("Waited For a Player")
	until #Players:GetPlayers() == RoundedPlayers
	
	print("Loaded Half the Server")
	
end)

Don’t forget to mark your post as the solution :slight_smile:

1 Like

MaxPlayer is the maximum players in the server, you asked how to find the half of the players the server can have right?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.