Hello! I was watching a YouTube tutorial on how to animate a tool. I learned the code, made some changes but I ran into a problem. If I place the Tool in the workspace, It works and the animation plays perfectly. Otherwise, if I place it into the StarterPack I get an error
Error: attempt to index nil with 'Humanoid'
(Local Script)
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild("Animation")
local drinkAnimation = character.Humanoid:LoadAnimation(animation)
local canDrink = true
local debounce = 7
script.Parent.Activated:Connect(function()
if canDrink then
canDrink = false
drinkAnimation:Play()
wait(.8)
script.Parent.Sound:Play()
wait(1)
character.Humanoid:TakeDamage(20)
wait(debounce)
canDrink = true
end
end)
I thought if I fire the Local Script to a basic script it might work but I haven't tried it yet,

1 comment
use character:WaitForChild("Humanoid") instead of character.Humanoid because the humanoid has not loaded when the script is run. it works when you place it in the workspace because the script is run after the humanoid is loaded