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.
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.
@Nkk2356 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().
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
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?
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