Problem with hitbox

im trying to make it so when the tools hitbox collides with a part, it grabs the parent of the part and gets children, the hitbox does work but whenever i try to get children it doesnt let me and fails to index with it. can anyone help me?

script.Parent.Hitbox.Touched:Connect(function(hit)
	if hit.Name == "epichitbox" then
		if not Debounce then 
		Debounce = true
		local Flower = hit.Parent:GetChildren()
		for i,v in pairs(Flower) do
			if v:IsA("Model") then
				if v:IsA("Part") then
				v:Destroy()
					end
				end
			end
		print("Caught a flower!")
		end
	end
end)

Is there any error messages or does it only print your statement at the end? It also seems like you never set your debounce back to false

actually, it only prints the “Caught flower!”, but it doesnt delete the flower. heres the hierarchy
Screenshot 2025-11-10 191607

Instead of iterating everything, why not just call Destroy() on hit.Parent?

1 Like

i dont get it, what do you mean by that?

Well you want to destroy the flower right? So instead of calling Destroy() on every single part, you could just call Destroy() on the flower model and Destroy() will automatically be called on all its children

well actually, it wont let me get the model by itself so thats the main reason why im using a for loop to just get the model since when i tried to get the model by itself it failed to index with it

What exactly does it say when you try to index hit.Parent

I would recommend that you try to print hit.Name and hit.Parent.Name at the start of your .Touched event

what the, when i tried again it suddenly worked again? the model worked as intended, i have no idea what i did but it suddenly works. maybe its because i tried to do a for loop to destroy the model.

Well im glad that it works fine now, goodluck with your script

1 Like

The reason you’re getting that indexing error is because of how your type checks are set up. You’re checking if something IsA("Model") and then immediately checking if it’s also a "Part", but an object can’t be both at once, so that part of the code never runs.

Here’s a cleaner version that should work fine:

local Debounce = false

script.Parent.Hitbox.Touched:Connect(function(hit)
	if hit.Name == "epichitbox" then
		if not Debounce then 
			Debounce = true
			local parent = hit.Parent
			if parent then
				for _, v in pairs(parent:GetChildren()) do
					if v:IsA("Part") then
						v:Destroy()
					end
				end
				print("Caught a flower!")
			end
			task.wait(0.5)
			Debounce = false
		end
	end
end)
1 Like

ah i see the issue, although the issue was solved i still appreciate you fixing it. thank you!

2 Likes

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