Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 2 years ago
Edited 2 years ago
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)

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 IncredibleTeamAidan 104 — 2y
0
Oh sorry, I didn't update the error, just give me a second.. mittomen28 5 — 2y
0
Players.mittomen28.PlayerScripts.AnimationHandler:7: attempt to index nil with 'Humanoid' --This is the error mittomen28 5 — 2y
0
LocalScripts can't play animations andarwniceguyjr 0 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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

Ad

Answer this question