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

How do i stop a looping animation when item is unequiped? Any help?

Asked by 7 years ago
Edited 7 years ago
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end
local humanoid = character.Humanoid
local animation = script.Parent.Hold
local player = game.Players.LocalPlayer
local note = script.Parent.Parent


function Equiped()
    humanoid:LoadAnimation(animation):Play()
end
function Unequiped()
    humanoid:LoadAnimation(animation):Stop()
end

note.Equipped:connect(Equiped)
note.Unequipped:connect(Unequiped)

humanoid:LoadAnimation(animation):Stop() <------- this doesnt work

2 answers

Log in to vote
0
Answered by 7 years ago

What you're trying to do on line 16: is loading an Animation then trying to stop an animation that isn't even playing. The way I would model your code would be somewhere along the lines of this:

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end
local humanoid = character.Humanoid
local animation = script.Parent.Hold
local animationLoaded 
local note = script.Parent.Parent

function Equiped()
    animationLoaded = humanoid:LoadAnimation(animation)
    animationLoaded:Play()
end
function Unequiped()
    if animationLoaded then
        animationLoaded:Stop()
        animationLoaded = nil
    end
end

note.Equipped:connect(Equiped)
note.Unequipped:connect(Unequiped)

Where animationLoaded is declared to be humanoid:LoadAnimation, we are now able to directly access and manipulate that exact animation that is played when equipped.

Ad
Log in to vote
0
Answered by 7 years ago

You my friend are trying to load an animation and stopping that animation, not the one playing. I have had this problem recently too. I use this method:

local animation = character.Humanoid:LoadAnimation(animationObject)

equip()
      animation:Play()
end
unequip()
      animation:Stop()
end

This is not a full script of course but just showing my method. I find it very easy to use and not complicated loading animations during the script, just get it all done at the beginning.

Answer this question