Attempt to index Nil with FindFirstChild

Hello, I’m currently working on my own gun system for my group and I cant figure out how to fix this error,
I’ve looked it up on DevForum but I can’t find an answer that works.

Here’s my code:

local player = game.Players.LocalPlayer

local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local animation = script.Parent.Idle
local animtrack = humanoid:LoadAnimation(animation)

local function equip()
	animtrack:Play()
end

local function unequip()
	animtrack:Stop()
end

script.Parent.Equipped:Connect(equip)
script.Parent.Unequipped:Connect(unequip)

I hope someone responds soon, thanks.

–Luke

Where is the FindFirstChild exactly? I can’t see it in your code.

You have to wait until the Character is loaded in to proceed. Use this: character = player.Character or player.CharacterAdded:wait()

Are you sure you pasted the right script? I don’t see FindFirstChild anywhere in the script?

Fixed it, its in the humanoid variable.

im getting this now…

Use character:WaitForChild("Humanoid") instead of character:FindFirstChild("Humanoid"). Again: you’re waiting until everything loads in.

1 Like