So I have two parts and the idea is that one part is supposed to move towards another stationary part and print a message.My code looks like this:

local tank = script.Parent
local debounce = false

for i = 1, 100 do
	tank.CFrame = tank.CFrame * CFrame.new(0, 0, -1)
	wait(0.1)
end

local function onTouch(hit)
	if debounce == false then
		debounce = true
	
	if hit.Name == "Wall" then 
		print("yes")	
		
	end
	end
end
		

tank.Touched:Connect(onTouch)


One part, the 'tank,' moves towards the other part as intended, but when it makes contact it doesn't print any message. Any ideas on why this is?

2 comments

0

Try putting the function and touched event before the for loop

0

This worked, thank you! I had to mess around with the debounce a bit to get it to work, but thanks. Any reason why it has to be in that order?