-- State manager
local lastState = Humanoid:GetState()
local function updateState()
local state = Humanoid:GetState()
local moving = Humanoid.MoveDirection.Magnitude > 0
-- Airborne or dead states
if state == Enum.HumanoidStateType.Jumping then
playAnimation("jump")
elseif state == Enum.HumanoidStateType.Freefall then
playAnimation("fall")
elseif state == Enum.HumanoidStateType.Dead then
playAnimation("idle") -- Dead defaults to idle for simplicity
else
-- Grounded states
if lastState == Enum.HumanoidStateType.Freefall then
playAnimation("land")
elseif moving then
playAnimation("run")
else
playAnimation("idle")
end
end
lastState = state
end