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

Loop won't run?

Asked by 8 years ago

I'm making a boat racing game. It starts off with a lobby, countdown, and yes or no for participation. If the player says yes, they will be teleported into a boat when the time transpires.

Everything is working until I want the race to end. The value for Reset turned to 1, but the timer does not reset and the player does not get teleported.

No output is showing.

Script 1-

local Yes = script.Parent.Yes
local No = script.Parent.No
local Timer = script.Parent.Timer
local Info = script.Parent.Info

local variable = Instance.new("NumberValue",game.Players.LocalPlayer) 
      variable.Name = "Participate"

function Participating() -- Participating feature inside of player
    Yes.Visible = false
    No.Visible = false
    game.Players.LocalPlayer.Participate.Value = 1 -- Makes Yes/No invisible
end
Yes.MouseButton1Down:connect(Participating)

function Participating()
    Yes.Visible = false
    No.Visible = false
    game.Players.LocalPlayer.Participate.Value = 0 -- Makes Yes/No invisible
end
No.MouseButton1Down:connect(Participating)

if game.Players.LocalPlayer.Parent == game.Players then
wait(1)
print("Found Players")
while game.Players.LocalPlayer.Participate.Value == 0 and game.Workspace.Race.Value == 0 do
            wait(0.05)
            Info.Text = "You are spectating the next race." -- If player said no they are told this
        end
    end

while game.Players.LocalPlayer.Participate.Value == 1 and game.Workspace.Race.Value == 0 do -- If player said yes they are told this
    wait(0.05)
    Info.Text = "You are participating in the next race!"

Script 2:

function reset() -- Timer
local time = 60 
for i = 1, 60 do
wait()
time = time - 1 
script.Parent.Text = tostring(time) 
end
game.Workspace.Start.Value = 1
game.Workspace.Race.Value = 1 -- When time runs out activate race/start values.
end

while game.Workspace.Race.Value == 0 do -- Start of Game
    wait(0.05)
        reset()
        game.StarterGui.ScreenGui.No.Visible = true
        game.StarterGui.ScreenGui.Yes.Visible = true
    end

while game.Workspace.Start.Value == 1 do -- Start of Race
    wait(0.05)
        game.StarterGui.ScreenGui.No.Visible = false
        game.StarterGui.ScreenGui.Yes.Visible = false
        script.Parent.Parent.Info.Text = "Race in progress.."
        for i, player in pairs(game.Players:GetChildren()) do
        local Character = player.Character
        if player.Participate.Value == 1 then
        Character:MoveTo(game.Workspace.JetSki.VehicleSeat.Position) --The player will teleport
        print("Teleported Players")
        game.Workspace.Start.Value = 0
        game.Workspace.Race.Value = 1
        end
    end
end

while game.Workspace.Reset.Value == 1 do -- End of Race
    wait(0.05)
        for i, player in pairs(game.Players:GetChildren()) do
        local Character = player.Character
        Character:MoveTo(game.Workspace.Lobby.Position)
        reset()
        game.StarterGui.ScreenGui.No.Visible = true
        game.StarterGui.ScreenGui.Yes.Visible = true
        game.Workspace.Reset.Value = 0
        end
    end
0
It looks like you don't change Reset to 1 anywhere in the script. Honestly, I would use the Changed event to do something like this, rather than loops. I'm not putting this as an answer because it doesn't specifically answer the question, but you're free to send me an IM or a PM on ROBLOX and ask me about it if you want. Lamar 45 — 8y
0
I think I'll do that Lamar, thanks. Tradesmark 65 — 8y

Answer this question