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

Is there a way to use "Break" on RunService?

Is there any method to break RunService? It seems like

game:GetService("RunService").Heartbeat:Connect(function()
print("Hello")
break
end)

Doesn't work...

2 answers

✓ Accepted answer

You could disconnect the connection after setting the connection to a variable. It would look something like this,

local Connection
Connection = RunService.Heartbeat:Connect(function()
	Connection:Disconnect()
end)

@iiNemo has a great answer if you want an event-connection-based solution. Sometimes you might want it in a loop, so you can use break like this:

while true do
    -- do your stuff
    if condition then
        break	
    end
    RunService.Heartbeat:Wait()
end

If you want to wait for Heartbeat only once, you can simply use RunService.Heartbeat:Wait() just like a wait() call.

This discussion is preserved as it was. New answers, comments, and votes are closed.