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

Having trouble with racing mechanic..?

Asked by 8 years ago

There are 3 values in the game.

Race: (When a race is in progress) Start: (When a race has just started) Reset: (When a race is over)

I'm running 3 scripts.

The first one is in Workspace:

while true do
wait(3)
if game.Workspace.Start.Value == 1 then
for i, player in pairs(game.Players:GetChildren()) do
    local Character = player.Character
    if player.Participate.Value == 1 then
    Character:MoveTo(game.Workspace.Test.Position)
    print("Got players")
    game.Workspace.Start.Value = 0
    game.Workspace.Race.Value = 1
end
end
end
end

The second one is a localscript inside of startergui:

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()
    Yes.Visible = false
    No.Visible = false
    game.Players.LocalPlayer.Participate.Value = 1
end
Yes.MouseButton1Down:connect(Participating)

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

if game.Players.LocalPlayer.Parent == game.Players then
wait(1)
print("Found Player!")
while true do
    wait(0.05)
    if game.Players.LocalPlayer.Participate.Value == 0
        then Info.Text = "You are spectating the next race." elseif 
            game.Players.LocalPlayer.Participate.Value == 1 then
            Info.Text = "You are participating in the next race!"
    end
end
end

The third script is inside of a gui timer:

function reset()
local time = 60 
for i = 1, 60 do
wait()
time = time - 1 
script.Parent.Text = tostring(time) 
game.Workspace.Start.Value = 1
game.Workspace.Race.Value = 1
    end
end

while true do
    wait(0.05)
    if game.Workspace.Race.Value == 0
        then 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.No.Visible = true
        end
    end
end

function race()
    script.Parent.Parent.Info.Text = "Race in progress.."
end

while true do
    wait(0.05)
    if game.Workspace.Race.Value == 1 then
        game.StarterGui.ScreenGui.No.Visible = false
        game.StarterGui.ScreenGui.No.Visible = false
        script.Parent.Parent.Info.Text = "Race in progress.."
    end
end

Everything works so far and there are no output errors. However, I would like the info gui to say "Race is in progress..", however, it shows either "You are participating in the next race!" or "You are spectating the next race." Any ideas?

1 answer

Log in to vote
1
Answered by
Lamar 45
8 years ago

Your loops are infinite, so the piece of code that changes the text never gets executed.

Try using your if statement conditions as conditions for the loop, instead, i.e.

while game.Workspace.Race.Value == 0 do
    --your code
end

This way, the loop will break when the value of Race changes and the next piece of code can be executed.

0
That's fantastic, thank you! Tradesmark 65 — 8y
Ad

Answer this question