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

Can you break a function and if so how?

Asked by
I_0KI 40
7 years ago

I'm making an animation script that uses welds that change C0s and C1s with lerp running on a Heartbeat function. I need to be able to stop the Heartbeat function when the welds C0 is the desired offset, however, "break" only works on loops. Is there any alternative to using break on a function?

0
You can use "return" to break functions Cuvette 246 — 7y
0
Thanks this works I_0KI 40 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
local desired = CFrame.new(0,0,0)
local signal = nil --We have to declare the signal first because we are disconnecting it when we initialize it
local weld = nil


signal = game:GetService("RunService").Heartbeat:Connect(function()
    if weld.C0 == desired then
        signal:Disconnect()
        signal = nil
    end
end)
Ad

Answer this question