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 make heartbeat run until a certain thing is true?

so i want it so heart beat runs then i can stop it if something is true im looking for a small script that would show an example of that

1 answer

✓ Accepted answer

You can disconnect it.

Here's an example:

local Thing = game.Workspace.Thing --Boolean Value
local HeartBeat = game:GetService("RunService").Heartbeat:Connect(function()
	print("Going!")
end)
Thing.Changed:Connect(function()
	if Thing.Value == true then
		HeartBeat:Disconnect()
		else
	end
end)

Once Thing is set to true, the HeartBeat should no longer run (meaning "Going!" will no longer print).

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