How do I prevent a race from starting if no players are ready?
I have two functions intended to stop players from joining a race if they're not ready.
One of them are to check if anyone is ready, but if no one is, how do I prevent the race from starting until someone is ready?
I'm not experiencing any errors.
I have a GUI called PlayGui.
When you join my game, you get to press "Play" to get into the lobby box.
When you do, "PlayGui.Enabled = false" happens.
That's what I consider being ready.
But how do I pause my race loop, if no one is ready yet?
Here's my attempt(it's bad)
Function 1(the one I want to fix) :
01 | function checkPlayers() |
02 | for _, player in pairs (game.Players:GetChildren()) do |
03 | if player.PlayerGui.PlayGui.Enabled = = false then |
06 | repeat wait() print ( "waiting" ) until player.PlayerGui.PlayGui.Enabled = = false |
Function 2(the script that teleports players to race track, happens after Function 1) :
01 | function teleportPlayers(target) |
02 | for _, player in pairs (game.Players:GetChildren()) do |
03 | if player.PlayerGui.PlayGui.Enabled = = false then |
04 | while player.Character = = nil do |
07 | local character = player.Character |
08 | local torso = character:WaitForChild( "Torso" ) |
09 | local rootpart = character:WaitForChild( "HumanoidRootPart" ) |
10 | torso.CFrame = target.CFrame |
11 | rootpart.Anchored = true |
13 | print ( "press play maybe?" ) |
Sorry if I'm being unclear, I'm tired and bad at english.