So I've designed a punching mechanic that triggers when you press 'E'; I haven't programmed damage yet, only an animation occurs, but I tested it in game and it didn't work. It works in Studio, what did I do wrong? The error that I get does not show up in studio, but rather in the output bar in-game. "Humanoid is not a valid member of Model"
local player = game:GetService'Players'.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local Hum = char.Humanoid -- This is the Humanoid the error is referring to.
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://855470374" -- Punching Animation
game:GetService("UserInputService").InputBegan:connect(function(Key)
if Key.KeyCode == Enum.KeyCode.E then
local animTrack = Hum:LoadAnimation(animation)
animTrack:Play() -- Initiate the Punching Animation
end
end)
Initially there was a problem with Char with it loading before the player did, which might somehow be correlated with this issue. If anyone could give any insight on how to fix this, I would be extremely grateful.

8 comments
I'm currently working on a My Hero Academia game solo, and this mechanic is (obviously) needed in pretty much any RPG. I'm about to shamelessly advertise my game, but uh... Check it out? https://www.roblox.com/games/823313848/Project-Horizon-v1-0-Early-Alpha
Is the script a LocalScript or Script? Where is the script located?
Localscript. Its located under StarterGui and then ScreenGui (for now)
The humanoid object may not have loaded at the time the script executed: try using the WaitForChild function and see what happens. :) (Parent:WaitForChild(Object_Name))
I don't understand what you mean- At least fully- But I'll try it!
Yeahhhhh... I don't understand what you mean. Sorry, I'm kind of an amateur programmer ;-;
If you could post an Answer explaining what you mean more in-depth, that would help a lot! Thank you for your help so far, though!
bump