Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Animation wont stop playing or it is overwriting the idle animation? [closed]

Asked by 4 years ago
Edited 4 years ago

This question already has an answer here:

Error:Humanioid is not a valid member of Model?

Summary:

Hello, I am trying to make a sprint/animation script but the walking animation wont stop playing when I am trying to play the idle animation. If you could help me it your be appreciated. My animations are all on movement and are mine. My script in is 'StarterCharacterScripts' and is a local script.

Video:

(copy an paste into search)https://gfycat.com/sorrowfulajarbluebottlejellyfish

Code:

local Player = game.Players.LocalPlayer
Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
repeat wait() until game.Players.LocalPlayer

m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)
    if key == "0" then 
        local run = Instance.new('Animation')
        run.AnimationId = 'rbxassetid://5013482632'
        runAnim = Character.Humanoid:LoadAnimation(run)
        runAnim:play()
        Character.Humanoid.WalkSpeed = 20
    end
end)

m.KeyUp:connect(function(key)
    if key == "0" then
        runAnim:stop()
        local walk = Instance.new('Animation')
        walk.AnimationId = 'rbxassetid://5013378526'
        walkAnim = Character.Humanoid:LoadAnimation(walk)
        walkAnim:Play()
        Character.Humanoid.WalkSpeed = 8
    end
end)
--start of idle animation--
Character.Humanoid.Running:Connect(function(speed)
    if Character.Humanoid.WalkSpeed < 0.5 then
        walkAnim:Stop() --turning off walk animation.
        local idle = Instance.new('Animation')
        idle.AnimationId = 'rbxassetid://5022482368'
        local idleAnim = Character.Humanoid:LoadAnimaton(idle) 
        idleAnim:Play()
    end
end
0
Are you sure you have the animation priorities correct? This is a common problem when using multiple animations. skyaz1 72 — 4y
0
yes, they all are on movement, astroblox17 -11 — 4y
0
Maybe try making the idle anim to priority idle, run animation to the highest priority, and the walk anim to right under the run anim, aside from that, the script seems fine to me. skyaz1 72 — 4y
0
also, local variables will only work inside the function you put them in, you need to move the local variables outside of the functions so you can reference the local variable in all of the functions. This is something that has to be fixed because you use local variables inside multiple functions, and the variable will not work outside of the function/loop it was assigned in skyaz1 72 — 4y
View all comments (2 more)
0
want me to just put the fixed script in answers and explain it? skyaz1 72 — 4y
0
Sure and thank you! astroblox17 -11 — 4y

Marked as Duplicate by JesseSong and youtubemasterWOW

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
skyaz1 72
4 years ago

Here is a script that fixes the local variable problem. Also, if this doesn't work, it's likely it is a animation priority problem, try using different priorities to allow specific animations to overwrite others to fix the problem

local Player = game.Players.LocalPlayer
local run =   local run = Instance.new('Animation')-- naming all the animation local variables up here instead
local run = Instance.new('Animation')   
local idle = Instance.new('Animation')  
Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
repeat wait() until game.Players.LocalPlayer

    m = game.Players.LocalPlayer:GetMouse()

    m.KeyDown:connect(function(key)
        if key == "0" then
            run.AnimationId = 'rbxassetid://5013482632'
            runAnim = Character.Humanoid:LoadAnimation(run)
            runAnim:play()
            Character.Humanoid.WalkSpeed = 20
        end
    end)

    m.KeyUp:connect(function(key)
        if key == "0" then
            runAnim:stop()
            walk.AnimationId = 'rbxassetid://5013378526'
            walkAnim = Character.Humanoid:LoadAnimation(walk)
            walkAnim:Play()
            Character.Humanoid.WalkSpeed = 8
        end
    end)
    --start of idle animation--
    Character.Humanoid.Running:Connect(function(speed)
        if Character.Humanoid.WalkSpeed < 0.5 then
            walkAnim:Stop() --turning off walk animation.

            idle.AnimationId = 'rbxassetid://5022482368'
            local idleAnim = Character.Humanoid:LoadAnimaton(idle)
            idleAnim:Play()
        end
    end

0
Also, if there is a problem with my answer, please go ahead and correct me skyaz1 72 — 4y
Ad