Heartbeat (Event)
From Legacy Roblox Wiki
![]() | |
Description | This event constantly happens. A "heartbeat" usually happens approximately every 1/30th of a second. |
---|---|
Member of: | RunService |
The following code would be put in a Script. The script can be placed in the Workspace.
This code does the following:
- The first line gets the Service RunService and puts it in the Variable "service".
- The second line creates the local variable "variable2" and sets its value to 5.
- The third line uses the wait function, which delays the script for 5 seconds. This is necessary because the "heartbeat" does not run regularly at the start of a game.
- The fourth line calls the function below when a "heartbeat" happens with the parameter "variable1", which is equal to the time between each heartbeat. The "end)" on the ninth line ends the function.
- The fifth, sixth and eighth line serve as a stopper. If they weren't there, the code inside of the if statement would be repeated every thirtieth of a second until the end of the game.
- The seventh line prints "The function returns: (variable1, which is 0.033333335071802)". It uses concatenation, which basically adds a variable to a string.