Why tool is not valid of member folder?

So, What i want to make is very simple like this


game from Outbreak [ALPHA]

and i remake it like this


i dont know why it said tool is not valid member of folder and I’ve tried many things like adding FindFirstChild(), print(), warn() and etc. but none of these are working. and this is my setup

Inside the handle script
wow

local db = false
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if db == false then
		db = true
		local backpack = plr:WaitForChild("Backpack")
		local tool = game.Workspace.Items.Tool or backpack
		if tool then
			tool.Parent = backpack
		end
		db = false
	end
end)

and the player script,i put it on StarterPlayerScript

backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
backpack.ChildAdded:Connect(function(child)
	local childamount = #backpack:GetChildren()
	if childamount > 1 then
		for i,tool in pairs(backpack:GetChildren()) do
			if tool ~= child then
				tool.Parent = game.Workspace.Items
				tool.Handle.Position = child.Handle.Position
			end
		end
	end
end)

Im sorry if you guys dont understand what im saying and what im trying to do, this is what i can do thanks

Try :WaitForChild()
(30 characters)

1 Like
local tool = game.Workspace.Items.Tool or backpack

try changing it to :

local tool = workspace.Items:WaitForChild("Tool")

At time of indexing, “tool” probably wasn’t instantiated which means it didn’t exist while referencing it.

Not sure when you are trying to find tool. But i am letting you know that when a tool is equipped it moves from where ever it was in backpack to the actually workspace inside the character. So if your trying to get tool inside the folder as soon as its equipped it wont work.

Well, its not working, it said infinite yield warn

that is preventable

set it to

local tool = workspace.Items:WaitForChild("Tool",10) 

The timeOut parameter is used to prevent the infinite yield error, so the thread doesn’t yield indefinitely and instead breaks and returns nil instead, if the instance was still not found

got an error It said infinite yield

@Friskyman321 did you read my post? It’s literally right above.

That error occurs when an instance was not returned within 5 seconds, this could be dangerous because you would otherwise be waiting for an instance to return when it doesn’t even exist.

Oh sorry dude, i just tested it out and i got an error it said “Attempt to set Players.Friskyman321.Backpack as it own Parent”

then you’re doing something terribly wrong, you are probably trying to , in another line of your code, set it to it’s own parent.

What’s the purpose of all this?

backpack = game.Players.LocalPlayer:WaitForChild("Backpack")

Also here you could just do

player = script.Parent 
backpack = player.Backpack

instead of getting Local Player through a long line of code, because anything in StarterPlayerScripts is replicated directly to the Player, with the Player as it’s Parent.