Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you break a function and if so how?

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?

2 comments

0

You can use "return" to break functions

0

Thanks this works

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.