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

"Attempted to index nil", how do i fix?

Ooh, if we could swear on this, i would be going crazy right now.

local tool = script.Parent
local handle = tool:FindFirstChild("Handle")

local character = tool.Parent

local Remote = tool.SwordMain

local player = game.Players.LocalPlayer

local humanoid = tool.Parent:FindFirstChild("Humanoid")

local mouse = player:GetMouse()

local equipped = false

function equip()
	equipped = true
	local idle = humanoid:LoadAnimation(tool.Idle)
	idle:Stop()
end

function unEquipped()
	equipped = false
	local idle = humanoid:LoadAnimation(tool.Idle)
	idle:Stop()
end

function mouse1Down()
	if equipped then
		Remote:FireServer(player, 15)
		print("PP")
	end
end

mouse.Button1Down:Connect(mouse1Down)
tool.Equipped:Connect(equip)
tool.Unequipped:Connect(unEquipped)

What the literal hell? why isn't this working?

In the output i get: Players.Actaully_Mine.Backpack.Sword.Client:18: attempt to index nil with 'LoadAnimation'

what is this

1 answer

Here's the script:

local tool = script.Parent
local handle = tool:FindFirstChild("Handle")

local character = tool.Parent

local Remote = tool.SwordMain

local player = game.Players.LocalPlayer

local humanoid = player.Character:WaitForChild("Humanoid")

local mouse = player:GetMouse()

local equipped = false

function equip()
    equipped = true
    local idle = humanoid:LoadAnimation(tool.Idle)
    idle:Play()
end

function unEquipped()
    equipped = false
    local idle = humanoid:LoadAnimation(tool.Idle)
    idle:Stop()
end

function mouse1Down()
    if equipped then
        Remote:FireServer(player, 15)
        print("PP")
    end
end

mouse.Button1Down:Connect(mouse1Down)
tool.Equipped:Connect(equip)
tool.Unequipped:Connect(unEquipped)

1 comment

0

the literal same thing i put

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