Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I prevent a race from starting if no players are ready?

Asked by
Dalamix 26
4 years ago

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) :

01function checkPlayers()
02    for _, player in pairs(game.Players:GetChildren()) do
03        if player.PlayerGui.PlayGui.Enabled == false then
04            break
05        else
06            repeat wait() print("waiting") until player.PlayerGui.PlayGui.Enabled == false
07            break
08        end
09 
10    end
11end

Function 2(the script that teleports players to race track, happens after Function 1) :

01function 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
05            wait()
06        end
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
12        else
13            print("press play maybe?")
14        end
15    end
16end

Sorry if I'm being unclear, I'm tired and bad at english.

0
Is this a round system? Ascarson4 138 — 4y
0
Well I have a game loop which basically starts a new race after the last one finished. Dalamix 26 — 4y

Answer this question