Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched event doesn't work when two blocks touch one another?

Asked by 5 years ago
Edited 5 years ago

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:

01local tank = script.Parent
02local debounce = false
03 
04for i = 1, 100 do
05    tank.CFrame = tank.CFrame * CFrame.new(0, 0, -1)
06    wait(0.1)
07end
08 
09local function onTouch(hit)
10    if debounce == false then
11        debounce = true
12 
13    if hit.Name == "Wall" then
14        print("yes")   
15 
View all 21 lines...

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?

0
Try putting the function and touched event before the for loop sheepposu 561 — 5y
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? jdmartine_z 15 — 5y

Answer this question