#my goddamn statemanager wont work for my animate script. help plaese im dying.

1 messages · Page 1 of 1 (latest)

wanton gazelle
#

-- 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

#

this is full script:

#

local Figure = script.Parent
local Humanoid = Figure:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

-- Animation setup (unchanged for simplicity)
local animTable = {
IdleAnim = "idle",
RunAnim = "run",
JumpAnim = "jump",
FallAnim = "fall",
LandAnim = "land"
}

local tracks = {}
local requiredAnims = { "IdleAnim", "RunAnim", "JumpAnim", "FallAnim", "LandAnim" }
local loadedAnims = 0

-- Load animations
local function configureAnimations(anim)
if anim:IsA("Animation") then
local state = animTable[anim.Name]
if state then
local success, track = pcall(Animator.LoadAnimation, Animator, anim)
if success and track then
track.Priority = Enum.AnimationPriority.Core
tracks[state] = track
loadedAnims = loadedAnims + 1
end
end
end
end

for _, track in ipairs(Animator:GetPlayingAnimationTracks()) do
track:Stop()
track:Destroy()
end

for _, anim in pairs(script:GetChildren()) do
configureAnimations(anim)
end

while loadedAnims < #requiredAnims do
local anim = script.ChildAdded:Wait()
configureAnimations(anim)
end

-- Play animation
local currentState
local function playAnimation(state)
if tracks[state] and currentState ~= state then
if currentState and tracks[currentState] then
tracks[currentState]:Stop()
end
tracks[state]:Play()
currentState = state
end
end

#

-- 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

-- Bind events
Humanoid.StateChanged:Connect(updateState)
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(updateState)

-- Initialize
if tracks.idle then
tracks.idle:Play()
currentState = "idle"
end

#

specifically the land animation doesn't work, it does idle instead and skips land animation.

#

nvm i fixed it