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?
✓ ANSWER ACCEPTED
Can you break a function and if so how?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
You can use "return" to break functions
Thanks this works