How do I find children in part

I am trying to make a system where NPC gives hint on where the tool spawns. While working on it I came across a problem, there is no children inside the spawners, or atleast that is what the script says. I made a system earlier when tools spawn on random spawners and it becomes a child of it. I looped through all the spawners and tried to see if it had a child but it kept saying no, but when clearly one of the spawners did have a child in it. My question is how do I find an unknown tool in a part.

Here is the script:

local toolTracker = game.Workspace:FindFirstChild("toolTracker")

for _,spawner in pairs(game.Workspace.Spawners:GetChildren()) do
	if spawner.Name == "toolSpawner" then
		toolSpawner = spawner
		tool = toolSpawner:GetChildren()
		if #tool > 0 then
			local chosen_spawner = toolSpawner
		else
			print("no")
		end
	end
end
2 Likes

You can use :FindFirstChildWhichIsA("Tool") and hopefully that would work.

Edit: I think this would work

local chosen_spawner

for _, spawner in pairs(game.Workspace.Spawners:GetChildren()) do
   if spawner.Name == "toolSpawner" and spawner:FindFirstChildWhichIsA("Tool") then
      chosen_spawner = spawner
   end
end

Thank you. This works. I forgot about the β€œIsA” concept

1 Like