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

How do I make this loops stop right when the character moves?

Asked by 4 years ago
function meditation(moving,equipped)
     while moving == false and equipped do
            progress.Size = UDim2.new(0,0,1,-4)
            progress:TweenSize(UDim2.new(1, -4, 1, -4),"Out","Linear",10,false)
            if equipped == false or moving == true then
                frame.Visible = false
                break
            end
            wait(10)
            updateMagic:FireServer(orbSize) 
    end
end

function moveDetect(speed)
    if equipped then
        if speed > 5 then
            moving = true
            meditating = false
            print("moving")
        else
            moving = false
            print("stoppedmoving")
        end
    end
end

The problem here is

if equipped == false or moving == true then
        frame.Visible = false
        break
end

only checks once so if moving = false while it checks once then during the 10second wait if moving turns true, it doesn't break the loop. How can i make it so that as soon as the char moves the while loop breaks?

0
Can you show the code for the variables? Geobloxia 251 — 4y
0
Use a while loop to keep checking and then break it when equipped is falsse or moving is true. Geobloxia 251 — 4y

1 answer

Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago

This might work:

while true do
    if not equipped or moving == true then
            frame.Visible = false
            break
    end
    wait(0.1) -- Cooldown so it doesn't crash
end
Ad

Answer this question