#Making Running Animation based on Humanoid.WalkSpeed

1 messages · Page 1 of 1 (latest)

glass coyote
#

Im trying to make the animation change from walking to running when the player walkspeed is 30 but I keep getting this error:
LoadAnimation requires an Animation object

The object is an animation, it has keyframes so that counts as animations right?

This is the code:

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local Keys = {}
local SpeedToChange = 0.05
local MaxSpeed = 30
local InitialSpeed = Humanoid.WalkSpeed

local WKey = Enum.KeyCode.W
local SKey = Enum.KeyCode.S
local AKey = Enum.KeyCode.A
local DKey = Enum.KeyCode.D

local RunAnim = script.RunAnim
local RunPlay = Humanoid.Animator:LoadAnimation(RunAnim)

UIS.InputBegan:Connect(function(Input, GameProcessed)
    if GameProcessed then return end

    local Keycode = Input.KeyCode
    if Keycode == WKey or Keycode == AKey or Keycode == SKey or Keycode == DKey then
        table.insert(Keys, Keycode)
    end
end)

UIS.InputEnded:Connect(function(Input, GameProcessed)
    if GameProcessed then return end

    local Keycode = Input.KeyCode
    if Keycode == WKey or Keycode == AKey or Keycode == SKey or Keycode == DKey then
        for i, v in Keys do
            if v == Keycode then
                table.remove(Keys, i)
                break
            end
        end
    end
end)

RunService.Heartbeat:Connect(function()
    if #Keys ~= 0 then
        Humanoid.WalkSpeed = math.min(Humanoid.WalkSpeed + SpeedToChange, MaxSpeed)
    else
        Humanoid.WalkSpeed = math.max(Humanoid.WalkSpeed - (SpeedToChange*3), InitialSpeed)
    end
    
    if Humanoid.WalkSpeed == MaxSpeed then
        RunPlay:Play()
    else 
        RunPlay:Stop()
    end
end)

thorn summit
glass coyote
#

Okay, I saved the animation to roblox but I cant find its id now

thorn summit
#

it gives you the id when you finish publishing

glass coyote
#

how do I look back at it

thorn summit
#

publish it again or overwrite, or look in your creator dashboard for the animations you uploaded

#

i think they're in your toolbox too

glass coyote
#

okay found it

#

but now

#

it only plays the first frame... the character keeps using the first frame... it doesnt play the full animation

#

does it keep looping the execution making it re run the first frame constantly?

glass coyote
#

done

glass coyote
thorn summit
glass coyote
#

So I can only wait and see?

glass coyote