Mine Still Blows Up Even When Variable Is Set To False

Hello, I am trying to make a landmine. I want it to not be able to explode for 10 seconds after you step on it. But it only turns invisible and turns of CanCollide but you can still explode it. What am I missing?

New scripter so I apologize if it’s a simple fix.


Another Way I tried

Edit: clarification

Move the creation of the CanExplode variable outside the touched function (at the very top of the script)


local Button = script.Parent
local CanExplode = true

    if CanExplode then
        --code that runs when it can explode
    --rest of your code

The reason yours is not working is because when you touch the button it automatically sets the variable CanExplode to true, even when it’s supposed to be false and not explode. Setting it outside of the touched function will keep that from being set to true every time the button is touched

Hope this helped!


You could set CanQuery on the part to false.

This worked! Thank you so much!

1 Like