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

How do I fix the attempt to index nil with 'Humanoid' error in line 4?

Asked by 4 years ago
Edited 4 years ago

I'm trying to to play a animation when I click with the tool equipped but this error keeps showing up. Here's my script:

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local Throw1 = script.Parent:FindFirstChild("Throw1")
local PlayA = character.Humanoid:LoadAnimation(Throw1)
local CanThrow = true
local dobounce = 1


script.Parent:Activated():Connect(function()
    if CanThrow then
        CanThrow = false
        PlayA:Play()
        wait (dobounce)
        CanThrow = true
    end
end)
0
Instead of using FindFirstChild("Throw1") on line 03 use WaitForChild("Throw1", 10) so that it waits until it finds the animation before trying to load it to the humanoid, which is probably what is causing the problem. Oxygen4Lyfe 408 — 4y
0
Instead of using FindFirstChild("Throw1") on line 03 use WaitForChild("Throw1", 10) so that it waits until it finds the animation before trying to load it to the humanoid, which is probably what is causing the problem. Oxygen4Lyfe 408 — 4y

Answer this question