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 4 years ago
Edited 4 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:

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?

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

Answer this question