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

How do I stop an animation from playing?

Asked by
Galicate 106
6 years ago
Edited 6 years ago

How would I stop an animation without making another animation? I tried anim:Stop() but it didnt work.

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
play = false

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "f") and play == false then
        anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
        anim:Play()
        Player.Character.Humanoid.WalkSpeed = 20
        play = true

        if(Key:lower() == "f") and play == true then
        anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
        anim:Stop()
        Player.Character.Humanoid.WalkSpeed = 16
        play = false

        end
        end
end)
0
What's the name of the animation in the script? AbsoluteZeroDEV 45 — 6y
0
anim Galicate 106 — 6y
0
Can you post a small snipbit of the script? AbsoluteZeroDEV 45 — 6y
0
yea Galicate 106 — 6y
0
Instead of having to press the key again with the if statement, what you could do is after the first if statement is declared, put a wait(Any variable you want) and then anim:Stop() AbsoluteZeroDEV 45 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

I'm not sure if you're wanting it to be timed; so here is what I came up with so that after a certain about of time; the animation will stop itself instead of having to KeyDown again. If this isn't what you wanted, you can let me know.

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Play = false

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "f") and play == false then
        anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
        anim:Play()
        Player.Character.Humanoid.Walkspeed = 20
        Play = true
        wait(5) -- Change this value to whatever you want
        anim:Stop()
        Player.Character.Humanoid.Walkspeed = 16 
        Play = false
    end
end)
0
TImed isnt really what i was looking for, im making a script that when you press f your character plays an animation and runs(gun idle) Galicate 106 — 6y
0
also the animation doesnt stop playing Galicate 106 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You're doing it correctly. anim:Play() Plays it.. anim:Stop() Stops it. Works for my animations. Probably other error in the script.

Answer this question