Forgive me if this has some obvious mistake in it, I’m very new to using RunService.
local RunService = game:GetService("RunService")
car = script.Parent
fOne = car.Parent.Parent.Floors.P1
RunService.Heartbeat:Connect(function(step)
if (car.Position.Y >= fOne.floor1.WorldPosition.Y - 1) then
if (car.Position.Y <= fOne.floor1.WorldPosition.Y + 1) then
fOne.atFloor.Value = true
print("at floor 1")
elseif (car.Position.Y >= fOne.floor1.WorldPosition.Y + 2) then
print("not at floor 1")
end
end
end)
I’ve looked at articles and posts with information or similar questions respectively, but none of them have actually explained how I should do this so this is my first go.
I feel like its wrong because this is constantly printing the part position rather than only printing when it’s actually changed.
It makes it effectively the same as a while loop. So, is this the correct way to use Heartbeat to detect when a position has changed?