Help with GetTouchingParts()

Hi all,
I’m experiencing an issue with the GetTouchingParts() function. My code obtains all the parts that are touching “copy”, and runs through all of them through a while loop, and if any of the touching parts are called “Floor”, then the copy is destroyed. However, when I run the code, it does print sometimes that V is “floor”, but when it does, “destroyed” is not printed. I think the fault may lie in the if statement, but I’m not sure how to fix it, so any help would be appreciated.

local touchingParts = copy.Structure.Floor:GetTouchingParts()
for i,v in pairs(touchingParts) do
	if v == "Floor" then
		copy:Destroy()
		print("destroyed")
	end
	print(v)
end

1 Like

You are comparing an instance with a string. Replace line 3 with if v.Name == "Floor" then.

2 Likes

I made a classic programming blunder. Thanks for the help!

1 Like

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