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

How to stop a for loop from pausing after running a function?

Asked by 4 years ago

Code:

canrun = true
for i = 0, .4, .01 do --move door
    local cframe = target.Parent.PrimaryPart.CFrame:lerp(destinationCFrame, i)
    target.Parent:SetPrimaryPartCFrame(cframe)
    if canrun then
        if i >= .15 then
            canrun = false
            closeHandle(target) --FUNCTION
        end
    end
    wait()
end -- end move

Here, I have a for loop that's supposed to move a door, using lerp. The door moving script runs fine without the function (labeled above in code). But when adding the function, the for loop pauses until the function is complete. This creates a pause of the door swinging open, as it pauses during its movement. All I need is to get the closeHandle() function to run if (i >= .15), without it pausing the for loop.

1
try using spawn() to execute closeHandle on a different thread aipiox123 1 — 4y
0
Thank you for the answer. RuskiKrolik 34 — 4y

Answer this question