How do i make a script that detects a part added in a folder in the workspace?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Can someone explain me why this script cant print anything

  1. What is the issue? Include screenshots / videos if possible!

I’m trying to use a folder to detect a part being added
and then do something with the part

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i looked at the API refrence

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

local Tools = game.Workspace.WorkspaceToolFolder

Tools.ChildAdded:Connect(function(child)

	local ToolFound = child:WaitForChild("Tool")
	if ToolFound then
		print("WE DID IT :)")
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

So, what is the problem ?
Is the problem is infinite yield possible or something ?

The problem is that the parameter child is the tool, so you’re trying to find a tool inside of a tool at the moment, all you have to do is remove the ToolFound variable and make the if statement if child then

1 Like

I’m getting a similar vibe from this code. ChildAdded is triggered, so the child is already loaded. I think they need to change WaitForChild to FindFirstChild.

1 Like

But the perameter in ChildAdded returns the Child, that being the tool.

If that’s the case, the “if child” statement is irrelevant. It should always come back true, right?

I’m assuming the “Tool” child is a kind of OOP safeguard from activating when something else is added to that folder. We would need to see the structure of the folder to know more.

Sorry i just used descendant added and saw that It did what i wanted the script to do
thanks for the help

2 Likes

This is always one of the possible outcomes of asking for help! Glad you got it figured out!

1 Like