Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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
local kick = Hum:LoadAnimation(animation)

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

The script is a LocalScript in

StarterPlayer > StarterPlayerScripts > LocalScript

2 answers

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

1 comment

0

It is redundant to put scripts inside StarterCharacterScripts on this situation, just do the second one

put a player.Character:WaitForChild("Humanoid") instead of player.Character.Humanoid

1 comment

0

I did that

This discussion is preserved as it was. New answers, comments, and votes are closed.