I'm trying to detect if a player is moving up or down based on the difference between the current and last Y position, but it doesn't seem to be working.
-- //Everything is defined above
loopCheck = Services['runService'].Heartbeat:connect(function(Rate)
local loopRate = workspace:GetRealPhysicsFPS()
local fastestMovement = speedStat.Value/loopRate -- //SpeedStat is their basespeed, 16 studs per second for example
-- //Movement calculations
if lastYPosition ~= nil then
print'a' -- //This is never printed
if Player.Character.Torso.Position.Y - lastYPosition >= fastestMovement*.9 then
moveDirection = 'Up'
elseif Player.Character.Torso.Position.Y - lastYPosition <= -fastestMovement*.9 then
moveDirection = 'Down'
else
moveDirection = 'Still'
end
end
local lastYPosition = Player.Character.Torso.Position.Y
print(moveDirection) -- //Always prints nil
print(lastYPosition) --//Correctly prints the y position
end)

1 comment
http://wiki.roblox.com/index.php?title=API:Class/Humanoid/MoveDirection