0

# Why does it say Attempt to index nil with Humanoid?

It ran an error and this is my code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Hum = player.Character.Humanoid
local animation = script.Animation

mouse.Button1Down:Connect(function()
kick:Play()
end)


The script is a LocalScript in

StarterPlayer > StarterPlayerScripts > LocalScript

2
Edited 1 year ago

I would recommend putting the script in StarterCharacterScripts since it modifies the character. Since the player loads in before the character when someone joins, it can cause issues like this where the character doesn't exist yet but it still tries to run the rest of the code.

Otherwise, you could probably put player.CharacterAdded:Wait() under the first line of your code to make sure the character exists before trying to do anything else if you don't want to move it

0
It is redundant to put scripts inside StarterCharacterScripts on this situation, just do the second one Xapelize 2658 — 1y
put a player.Character:WaitForChild("Humanoid") instead of player.Character.Humanoid