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

Game freezes with two co-routines running at once?

Asked by 8 years ago

Hi,

I've created a script (shown below) which has 2 co-routines. Both of them have wait() in them, however the game seems to freeze and crash if I attempt to run this code by clicking a button.

function changeSignF(sign, destVal)
    local mainSign = script.Parent.MainSign.SurfaceGui.Framea.Frame.TextLabel
    repeat
        for j = 1,destVal do
            for i = 0,1,0.2 do
                mainSign.Parent.Position = UDim2.new(0,0,i,0)
                wait()
            end

            mainSign.Text = tab[j][1]

            for i = -1,0,0.2 do
                mainSign.Parent.Position = UDim2.new(0,0,i,0)
                wait()
            end 
        end
    until mainSign.Text == sign
end

function changeNumF(num, destVal)
    local mainNum = script.Parent.MainNum.SurfaceGui.Framea.Frame.TextLabel
    wait(2)
    repeat
        for j = 1,destVal,-1 do
            for i = 0,-1,-0.2 do
                mainNum.Parent.Position = UDim2.new(0,0,i,0)
                wait()
            end

            mainNum.Text = tab[j][2]

            for i = 1,0,-0.2 do
                mainNum.Parent.Position = UDim2.new(0,0,i,0)
                wait()
            end
        end
    until mainNum.Text == num
end

script.Parent.Value.Changed:connect(function()
    local num = script.Parent.Value 
    local tabNum = #tab + 1
    if num.Value > 0 and num.Value < tabNum then
        script.Parent.Sign.SurfaceGui.TextLabel.Text = tab[num.Value][1]
        script.Parent.Num.SurfaceGui.TextLabel.Text = tab[num.Value][2]
        script.Parent.Via.SurfaceGui.TextLabel.Text = tab[num.Value][3] 
    end

    if num.Value == tabNum then
        num.Value = 0
    end

    if num.Value == -1 then
        num.Value = tabNum - 1
    end
end)

script.Parent.OK.ClickDetector.MouseClick:connect(function()
    local sign = script.Parent.Sign.SurfaceGui.TextLabel.Text
    local num = script.Parent.Num.SurfaceGui.TextLabel.Text
    local via = script.Parent.Via.SurfaceGui.TextLabel.Text
    local mainSign = script.Parent.MainSign.SurfaceGui.Framea.Frame.TextLabel
    local mainNum = script.Parent.MainNum.SurfaceGui.Framea.Frame.TextLabel
    local secNum = script.Parent.SecNum.SurfaceGui.Framea.Frame.TextLabel
    local thiNum = script.Parent.ThiNum.SurfaceGui.Framea.Frame.TextLabel
    local mainVia = script.Parent.MainVia.SurfaceGui.Framea.Frame.TextLabel
    local destVal = script.Parent.Value.Value
    local changeSign = coroutine.create(changeSignF)
    coroutine.resume(changeSign, sign, destVal)
    local changeNum = coroutine.create(changeNumF)
    coroutine.resume(changeNum, num, destVal)
end)

This should run perfectly normal since there are waits in there. However, if I add in a wait on changeNumF() after the repeat on line 5, it doesn't seem to work at all. Anyone know what's freezing the game?

Answer this question