:GetTouchingParts not working

print("a")
local Debounce = false
while true do

		for i , v in ipairs(script.Parent.Parent.Range:GetTouchingParts()) do
			if v:FindFirstChild("Aim") then
			script.Parent.Parent.Union.CFrame = CFrame.new(script.Parent.Parent.Union.Position , Vector3.new(0 , v.WorldPosition.Y , 0 ))
			print("123")
			end
		end
wait(0.1)
end





123 never prints, which leads me to think the collisions are not registering for some reason, despit the fact that the parts are actually touching.

1 Like

What happens if you print(123) earlier in the code? You should replace ipairs() with pairs(). What if you print out touching parts?

print(script.Parent.Parent.Range:GetTouchingParts())

EDIT. While wait() loops are to be avoided. Use RunService:Heartbeat:Wait() instead, until RunService:PostSimulation:Wait() is implemented. I think wait(0.1) is alright and writen deliberately here.

@BlueMinionIW actually, wait() should never be used. It is part of 30Hz pipeline, and costs you consistency and reliability in your code. Delays are very common and it is based on pooling, which is worse for performance than RunService.Heartbeat:Wait().

1 Like

What do you mean? Try to explain it better so I can understand.

1 Like

I wouldn’t use that because it makes it more complicated and also uses less lines of code and also does not use a script timeout.

ok, the list does print correctly, but 123 still does not print, despite the fact that is should run once.

Instead, I would try making a variable for "Aim" and replacing v:FindFirstChild("Aim") with v = Aim if v = Aim then instead.

Try this code.

print("a")

local Debounce = false
while wait() do

	for i , v in ipairs(script.Parent.Parent.Range:GetTouchingParts()) do
        v = -- Make the variable here
		if v = Aim then
		   script.Parent.Parent.Union.CFrame = CFrame.new(script.Parent.Parent.Union.Position , Vector3.new(0 , v.WorldPosition.Y , 0 ))
		   print("123")
	  end
  end

end

1 Like

Yeah but since the part does vary I have to use v:FindFirstChild(). Or did I not understand correctly?

You might have misunderstood. Maybe I’m wrong but I think I’m right tho.

1 Like

OH, I get it now, I found out I was using a wrong part for testing, thatpart did not have an attachment named Aim, now 123 does print, but the Union still doesnt turn, Perhaps that has something to do with the parts its constrainted to?

1 Like

So I didn’t help? }}}}}}}}}}}}

1 Like

Well, yes, but actually no, sorry my bad.

Wdym? }}}}}}}}}}}}}}}}}}}}}}}}}}

1 Like

The problem was that the part did not have an Attachment named Aim. That is why 123 did not print, not becuase it did not touch. Although, the part still doesnt move