M1Connection = RS.Heartbeat:Connect(function()
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
M1(animation)
end
wait(0.7)
end)
it has a wait?
M1Connection = RS.Heartbeat:Connect(function()
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
M1(animation)
end
wait(0.7)
end)
it has a wait?
Heartbeat is an event not a loop.
It basically does this:
Heartbeat 1 : Connects - runs code starts to wait
Heartbeat 2: Connects - runs code starts to wait
…
Heartbeat 42 Connects - runs code starts to wait
Heartbeat 1 - finishes waiting
Heartbeat 43 Connects - runs code starts to wait
Heartbeat 2 - finishes waiting
Yes I know that, but what I mean is that this is running very quick like every 0.001 second, but I’ve put a wait in there so i don’t know why?
Each heartbeat a new ‘thread’ is created, each are separate from each other, the second heartbeat doesn’t need to wait for the first one to finish before it starts running. The approx time between heartbeats is 1/60 or 0.017 seconds.
The .Heartbeat event runs every server frame (about 250 FPS).
Remember that events are all seperate to each other, so you are waiting 0.7 seconds for nothing every frame.
Edit: I didn’t see the guy above me
Like @Wigglyaa and @OfficiallyThe_Epic said, each event subprogram runs in its own separate thread. You can debounce it to achieve your desired behaviour.
local rs = game:GetService("RunService")
local db = false
local function onHeartbeat(dt)
if db then return nil end
db = true
--do stuff
task.wait(1)
db = false
end
rs.Heartbeat:Connect(onHeartbeat)
Try stepped… heartbeat is just too fast.