New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Animation won't stop even when told to on unequipping a tool? [Read Desc]

Asked by 1 year ago

I am making a game which involves me to have a animation when the tool isn't used when its equipped. However while I have gotten the equipping animation down when I unequip the tool it wont stop. In the output it says "attempt to call a nil value." Again I'm not wanting a remodel of the script I want to know how to fix it.

The script:

local deb= false
local timeLength= 1
local photographer = game.Players.LocalPlayer
local AnimationID = script.ID.Value
local tool = script.Parent
Humanoid = photographer.Character.Humanoid


function onActivation()
    if deb == false then deb = true
    Humanoid.WalkSpeed = 0
    game.ServerScriptService.Events.AddPhotos:FireServer()
    local animation = Instance.new("Animation")
    animation.Name = "Shoot"
    animation.Parent = photographer
    animation.AnimationId = "http://www.roblox.com/Asset?ID=2225545721"
    local animTrack = Humanoid:LoadAnimation(animation)
    animTrack:Play()
wait(0.4)
animTrack:Destroy()
Humanoid.WalkSpeed = 16
    wait(1)
    deb = false
    else end
end
function onEquipped()
local anim = Instance.new("Animation")
    anim.Name = "Idle"
    anim.AnimationId = "rbxassetid://"..AnimationID
    local h = Humanoid:LoadAnimation(anim)
    h:Play()
    function unEquipped()
        h:Stop()
    end
    end
script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(unEquipped)
script.Parent.Activated:Connect(onActivation)

If anyone knows the reason can you please help. Thanks.

1 answer

Log in to vote
1
Answered by
ABK2017 392 Moderation Voter
1 year ago

Stop isn’t a valid member of animation, the AminationTrack has the Stop function.

Ad

Answer this question