I am a noob to scripting. I have been trying to assign an animation to play when I press an key. When I try this script it says "Players.starmelvin.PlayerScripts.LocalScript:8: attempt to index nil with 'Humanoid' ".
I searched it up and what I found kept saying that it means that the parent changed. I don't get how the parent changed and I need help. I am pretty trash at scripting so don't expect it to be really complicated.
Also keep in mind the child of the script is the animation and the animation id and stuff. Idk how to describe it. Basically I dragged the animation into the script. I think that means its a child.
local WaveAnimation = script.WaveAnimation
local UserInputService = game:GetService("UserInputService")
wait(1)
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char.Humanoid
local WaveAnimationTrack = hum:LoadAnimation(WaveAnimation)
UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
wait(1.35)
WaveAnimationTrack:Play()
end
end)
Edit: Ok I have fixed the script based on a comment that I got which helped. But it appears it only works once. Right after I made the change and fixed it and then I tested the game it worked fine. But when I tried testing it again it stopped working and won't work again.

8 comments
Please use a Lua Code block, so we can see the code better
use char:WaitForChild("Humanoid") and make sure it's a local script because UserInputService never work on normal scripts
last one, would you mind putting the loadAnimation inside UIS, make a new space and put it in line 15, and :Play() will be in line 16 so as I said make a new space
Ok it worked thanks
If your question was answered through the comments, please edit your post and add [SOLVED] to the title.
Uh well It worked but its doesn't work all the time the same error still comes up sometimes
I made an edit for the 2nd problem
LocalAnimation is deprecated now from Humanoid, search up. Use the LoadAnimation from Animator.