Hey, I'm recently new to Lua, I have a basic understanding of html and so I can understand some things but I'm really stuck on this bit of coding for my game.
This is a localscript for a tool, and I'm trying to make it so when the tool is equipped and you press the 'E' key, it will play an animation and sound. This does work, however when I unequip the tool and press 'E' I get an error saying 'Humanoid is not a valid member of backpack - Line 14', and it breaks the script completely so when i re-equip the tool nothing happens when I press E.
This is really frustrating as it seems to be an easy fix but I can't see anything wrong with my 'local Animation', thanks in advance for any help/advice!
local debounce = false
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://5147845886"
local CrateAnimation = Instance.new("Animation")
CrateAnimation.Parent = script
CrateAnimation.AnimationId = "rbxassetid://5150418068"
UserInputService = game:GetService("UserInputService")
script.Parent.Equipped:connect(function()
UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.E then
if not debounce then
debounce = true
local Animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Animation)
Animation:Play()
sound:Play()
wait(3)
Animation:Stop()
sound:Stop()
debounce = false
end
end
end)
end)
Location of script:
StarterPack: Tool: LocalScript, Handle, Animation,
LocalScript is located within the Tool which is located in the StarterPack

2 comments
Where is this script located? Can you provide the heirarchy?
Oh apologies, I've edited my post now to provide that information. The LocalScript along with the Animation is located within a Tool which is located within the StarterPack. Hope this is what u meant.