Hello, I have a small issue today
i’m making a system that logs the position of the player whenever they move but i don’t exactly know how i’d do this properly.
I saw that the usage of MoveDirection is something used however upon using this, I came to the realization that the Y axis isn’t updated if the player is Falling or Jumping, which can provide some inconsistencies.
I was then redirected to Heartbeat but this fires every frame after the physics is calculated (or something along those lines) which also works but sounds somewhat expensive in terms of preformance. since every Client will have this, I don’t think this’d be the best option. Especially considering that I noticed frame drops whenever I added a Print statement to the Function.
I then thought of trying to combine these two together;
Hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Hum.MoveDirection.Magnitude > 0 then
TrackFunction = RS.Heartbeat:Connect(function()
local YAxis = HRP.Position.Y
print("Heartbeat is Running")
script.Parent.DepthStat.Text = "Depth: "..math.round(YAxis)
if Hum.MoveDirection.Magnitude <= 0 and Hum:GetState() ~= Enum.HumanoidStateType.Freefall then
TrackFunction:Disconnect()
print("Disconnected function")
end
end)
end
end)
The idea behind this was that the script would check if the player is moving, if they are, then the heartbeat function is started. which logs the y axis of the player and updates it to a GUI. it also checks if the player is in the Freefall state or if the player’s magnitude from MoveDirection is at 0. (i know that MoveDirection can’t go below zero that was just habit.)
If it checks that either of these values are true, it should disconnect the heartbeat function, stopping the entire function until the movedirection changes to being above one again.
This script doesnt work however;

The function just re-activates itself even if the Player is standing still.
I’m assuming I misunderstand what :Disconnect() actually does? unsure.
All of this is to just check the Player’s Y Position whenever it changes (Before anyone says: No, You can’t use GetPropertyChangedSignal on the Player’s Position. I’ve tried this already and it is never activated. I was told this was because it only detects changes made by scripts and not physic changes.)
Any help? I’m looking for something that won’t just run in the background 24/7 like Heartbeat but I do want it to fire constantly as long as the player is moving. Thank you.
(^^ when I say “Players” I’m referring to their character.)