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

Why the script can't find the humanoid???

local Attackanim = script.Attackanim

wait(1)

local vPlayer = game.Players.LocalPlayer
local character = vPlayer.Character
local humanoid = character.Humanoid

local AnimationTrack = humanoid:LoadAnimation(Attackanim)

local mouse = vPlayer:GetMouse()

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

Please help me, the error code: Players.mittomen28.PlayerScripts.AnimationHandler:7: attempt to index nil with 'Humanoid'

Also, this is a local script (ofc)

4 comments

0

is the error copy and pasted? it says "FindFirtChild", when the command should be "FindFirstChild" it's probably a simple typo, that's all

0

Oh sorry, I didn't update the error, just give me a second..

0

Players.mittomen28.PlayerScripts.AnimationHandler:7: attempt to index nil with 'Humanoid' --This is the error

0

LocalScripts can't play animations

1 answer

Attempt to index nil with humanoid. From this we should know that the character is the one with a nil value meaning the character isn't there. Sometimes the script loads in before the character does and whent he script runs, there wont be a character yet. You can solve this by waiting for the character to join if there is none.

if not character then
	character = vplayer.CharacterAdded:Wait()
end

It should work if you insert this between lines 6 and 7

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