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) :
function checkPlayers() for _, player in pairs(game.Players:GetChildren()) do if player.PlayerGui.PlayGui.Enabled == false then break else repeat wait() print("waiting") until player.PlayerGui.PlayGui.Enabled == false break end end end
Function 2(the script that teleports players to race track, happens after Function 1) :
function teleportPlayers(target) for _, player in pairs(game.Players:GetChildren()) do if player.PlayerGui.PlayGui.Enabled == false then while player.Character == nil do wait() end local character = player.Character local torso = character:WaitForChild("Torso") local rootpart = character:WaitForChild("HumanoidRootPart") torso.CFrame = target.CFrame rootpart.Anchored = true else print("press play maybe?") end end end
Sorry if I'm being unclear, I'm tired and bad at english.