Script doesn't find tool in backpack

Hello!
I want to get these 2 tools in a LocalScript after they have been cloned from the StarterPack:

local placetool = player:WaitForChild("Backpack"):WaitForChild("Blocks")
local deletetool = player:WaitForChild("Backpack"):WaitForChild("Delete")

However, it doesn’t find it and I get this error, although it is actually in the Backpack within 5 seconds.

3
1 2

2 Likes

Add the second parameter of WaitForChild at it.

WaitForChild("Blocks", 6)

The second parameter tells how much time at maximum it should wait for it.

Maybe try something like this

game.Players.PlayerAdded:Connect(function(player)
	local blocksTool
	local deleteTool
	
	coroutine.resume(coroutine.create(function()
		repeat wait() until blocksTool ~= nil and deleteTool ~= nil do
			print("Got tools")
		end
	end))
	
	player.Backpack.ChildAdded:Connect(function(object)
		if object:IsA("Tool") then
			if object.Name == "Blocks" then
				blocksTool = object
			elseif object.Name == "Delete" then
				deleteTool = object
			end
		end
	end)
end)

Haven’t tested it so let me know if it changes anything.

You can try and set it nil/a dummy variable the script can work with, and when a child is added to the backpack, it checks for the tool and sets it to that.

Actually you only need to do player.Backpack.ChildAdded:Wait() and then you use these variables

Unfortunately, none of them work. It seems like there is no ChildAdded event fired, so the Backpack is empty for the script, which it definitely isn’t.

As I said you should add the second parameter for WaitForChild.

It will return nil only when the time you specified passes, Since you are sure it comes within 5 seconds then you can just do it 6 to 15 seconds.

I see the tools definitely within 5 seconds in the Backpack, but the script can’t get them. It doesn’t matter if the wait time is 5 or 15 seconds, since the script finds nothing.

Try doing it, also where the script is at?

I tried it already and it’s a LocalScript in StarterPlayerScripts.

What is the variable you did for player?

local player = game.Players.LocalPlayer

As I said you should try doing the second variable, it can help at fixing most errors

I tried that with 10, 15 and 20 seconds. It doesn’t find the tools and because the variables are nil, the code below has errors.

A server-side script can’t get the tools either and it doesn’t work in Roblox Player as well.

Thats weird, there shouldnt have any bugs regarding this.

Weird. This doesn’t work too.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		game.ServerStorage.Blocks:Clone().Parent = plr:WaitForChild("Backpack")
		game.ServerStorage.Delete:Clone().Parent = plr:WaitForChild("Backpack")
	end)
end)

Try player.Backpack.FindFirstChild("ToolName")

Okay, that fixed the variable problem. :slight_smile:
Now I get this error:

Players.Vaschex.PlayerScripts.ClientBuilding:24: attempt to index nil with ‘Equipped’

local placetool = player:WaitForChild("Backpack"):FindFirstChild("Blocks")
local deletetool = player:WaitForChild("Backpack"):FindFirstChild("Delete")

placetool.Equipped:Connect(function()
--code
end)

Is the tool equipped? (30 chars)

Nope, it gives the error when starting the game.