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.
