I Recommend To Parent The Tool Instead Of Using EquipTool()

If You Trying To FindFirstChild() Or WaitForChild() Something Inside The Tool, It’ll Make an Error Like This

I Rather Use Tool.Parent Than EquipTool(Tool)

Nope

eah

I Hope It Helps!

thx bro. now i need to try this

they made the function for a reason…

Attempt to index nil with 'FindFirstChild'

Backpack is nil, thus you can’t run “FindFirstChild”. It’s possible that Backpack may have not replicated yet, thus trying to index/access “FindFirstChild” from a non-existent object, which is supposed to be a Backpack object.

The solution you have provided is not a fix or actual recommendation, but rather, a misunderstanding. Please analyse your code properly, thoroughly, and logically before making conclusions. As the above person said, EquipTool has a purpose.

Assuming all variables are readied, this is the fix:

local Player -- I assume Backpack is the Backpack object under a Player.
local Backpack = Player:WaitForChild("Backpack")

local ToolName = "Sword"
local Tool = Backpack:FindForChild(ToolName)

if Tool == nil then
	error(`{ToolName} is not a valid Tool.`)
end

Humanoid:EquipTool(Tool)
A working, complete, server-side example (under ServerScriptService):
local function WaitForChildWhichIsA(parent : Instance, className : string, timeOut : number?)
	if parent == nil or (not (typeof(parent) == "Instance")) then
		error("Parent not provided or is not an object.")
	end

	if className == nil or (not (typeof(className) == "string")) then
		error("Class name must be a string")
	end

	local ChildFound = parent:FindFirstChildWhichIsA(className)

	if ChildFound == nil then
		local RunService = game:GetService("RunService")
		local Deadline = tick() + (timeOut or 0)

		repeat
			RunService.Heartbeat:Wait()
			ChildFound = parent:FindFirstChildWhichIsA(className)
		until ChildFound or (if timeOut ~= nil then tick() > Deadline else false)
	end

	return ChildFound
end

local Players = game:GetService("Players")
local CharacterAddedConnections = {}

Players.PlayerAdded:Connect(function(Player)
	CharacterAddedConnections[Player] = Player.CharacterAdded:Connect(function(New_Character : Model)
		local Backpack = Player:WaitForChild("Backpack")
		
		local Humanoid : Humanoid
		local Character = Player.Character do
			if not Character then
				Character = Player.CharacterAdded:Wait()
			end
		end

		Humanoid = WaitForChildWhichIsA(Character, "Humanoid", 10)
		
		local ToolName = "Sword"
		local Tool = Backpack:FindFirstChild(ToolName)

		if Tool == nil then
			error(`{ToolName} is not a valid Tool.`)
		end

		Humanoid:EquipTool(Tool)
	end)
end)

Players.PlayerRemoving:Connect(function(Player)
	CharacterAddedConnections[Player]:Disconnect()
	CharacterAddedConnections[Player] = nil
end)
Edits
  1. Fixed code display of server-side example.
  2. Added more explanation as to how Backpack = nil happens.
2 Likes

This should go into #resources:community-tutorials

Not exactly if the given information doesn’t actually solve a problem.

Oh, sorry for my mistake :sweat_smile:

limit

1 Like

That is unfortunately not how it works. If you are able to read and understand what the error means then you’ll understand that your recommendation of using a different method to relocate the Tool to a character is completely irrelevant.

3 Likes

Thank you guys for the feedbacks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.