Is there any method to break RunService? It seems like
1 | game:GetService( "RunService" ).Heartbeat:Connect( function () |
2 | print ( "Hello" ) |
3 | break |
4 | end ) |
Doesn't work...
You could disconnect the connection after setting the connection to a variable. It would look something like this,
1 | local Connection |
2 | Connection = RunService.Heartbeat:Connect( function () |
3 | Connection:Disconnect() |
4 | 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:
1 | while true do |
2 | -- do your stuff |
3 | if condition then |
4 | break |
5 | end |
6 | RunService.Heartbeat:Wait() |
7 | end |
If you want to wait for Heartbeat only once, you can simply use RunService.Heartbeat:Wait()
just like a wait()
call.