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

how do i stop a animation when im not holding a tool?

Asked by
3wdo 198
5 years ago

i am making a simulator game so i made a tool and it can load an animation but i cant stop it. my script might look dumb but im still a beginner scripter:

script.Parent.Equipped:Connect(function()
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
    animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Hold)
    animation:Play()
end)

script.Parent.Unequipped:Connect(function()
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Hold)
    animation:Stop()
end)

that last part i cant stop the animation

btw i named the animation hold because im holding a tool

0
Learn python instead. Lua is shi-t! metalive 0 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

What I do when i encounter this problem, is create a separate animation and i name it "security", which basically stops all animations.

Tutorial

First, load in your animation editor onto a rig... thing

Then, you basically disable all of the parts ( Can be done by clicking every single box to the left of your editor )

So finally, you just add that animation onto your tool (or whatever)

Final code:

script.Parent.Equipped:Connect(function()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Hold)
        animation:Play()
end)

script.Parent.Unequipped:Connect(function()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
        animation =game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Hold)
        animation:Stop()
    ----ADDED CODE
    SecurityAn = (Ur animation)
    SecurityAn:Play
    wait(0.5)
    SecurityAn:Stop()
end)

Hope this was clear :)

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Simple solution! Just use the unequipped function like for example:

Script.Parent.Unequipped:Connect(function()

So your solution is:

Script.Parent.Unequipped:Connect(function() -- Does a function on tool unequipped.
animation:Stop() -- Stops the animation.

Make sure you put that under all that line of code! It should work. If you want to make it do anything else on unequipped, then just simply put what you want to do under the unequipped event like this:

Script.Parent.Unequipped:Connect(function()
-- Put whatever you want to make the tool do on unequipped here.

Answer this question