I have this scirpt
local debounce = false function onTouch(hit) wait(30) if not debounce then debounce = true hit.Anchored = false local explosion = Instance.new("Explosion", hit) explosion.DestroyJointRadiusPercent = 0 explosion.Position = hit.Position return end debounce = false end script.Parent.Touched:connect(onTouch)
I want to make it so even though the player touche's the bricks, there has to be a wait/reload of 30 seconds before the actual script will go. However, the wait(30) does not seem to be doing anything.
function onTouch(hit) -- I set a function and named it 'onTouch' with a parameter of 'hit' just like you did. if debounce then return end -- Here is where it gets different I checked if it is true and if it is then it returns end. However, in this case our debounce would be false. I know I didn't set the debounce at the very top but, that's because it auto-matically thinks of it as false. debounce = true -- I set the debounce to true right here and think of this as if you're closing the gate to a function. So, when you set this to true this function can not be re-run unless you set the debounce back to false. hit.Anchored = false -- Your code local explosion = Instance.new("Explosion", hit) -- Your code explosion.DestroyJointRadiusPercent = 0 -- Your code explosion.Position = hit.Position -- Your code wait(30) -- I moved the wait from the beginning of the function to the bottom so that it doesn't wait at the beginning. It fires it once and then waits for this time and then sets it to false. That is when it opens the gate to the function so that it can be re-run. debounce = false -- It opens the gate to the function meaning that the function can run now since you set the debounce to false and the if statement would agree with the condition now. end -- This is an end for the function. If you've noticed I've already put an end to that if statement up there which is what it returns if debounce is true. script.Parent.Touched:connect(onTouch) -- Connecting the function to an event.
~~ KingLoneCat
The part itself might have welds or joints, or some connection to other parts (this is my only possible explanation for the anchored issue). For the explosion, remember that explosion instances have a Position property that needs to be set to the part's position (http://wiki.roblox.com/index.php?title=API:Class/Explosion/Position).
Hope this has helped in any way :)