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

Why is my debounce not working even though I think I did it correctly?

Asked by
Xyternal 247 Moderation Voter
2 years ago
Edited 2 years ago

So I did some tutorials here and there, and I'm trying to make the part blow up up every 55 seconds if it is touching the current part. But it won't even say that it's touching the model when I put it right on it.

local RESET_SECONDS = 1
local isTouched = false 
if not isTouched then  
    isTouched = true  
    script.Parent.Touched:Connect(function(obj)
        if obj:IsDescendantOf(game.workspace.car) then
            local explosion = Instance.new("Explosion")
            explosion.BlastRadius = 1000000


            explosion.Parent = game.Workspace
            explosion.Position = script.Parent.Position
            print('model touched')

        else
            print("couldn't find model")
        end

        wait(55)
    end)
    wait(RESET_SECONDS)  -- Wait for reset time duration
    isTouched = false  -- Reset variable to false
end


0
line 6, make it game.Workspace instead of game.workspace AProgrammR 398 — 2y
0
yeah that doesn't help Xyternal 247 — 2y

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago

Your doing it wrong, you should be checking the isTouched inside of the Touched event:

local RESET_SECONDS = 1

local isTouched = false

script.Parent.Touched:Connect(function()
    if not isTouched then
        isTouched = true

        -- Code for the explosion thing

        task.wait(resetSeconds)
        isTouched = false
    end
end

Also can you give me the link for the tutorial because I think the person made the tutorial is cool

1
pov: people dont understand the meaning of 'scope' :pensive: greatneil80 2647 — 2y
0
just search up debounce tutorial, and he'll have the answer. Xyternal 247 — 2y
Ad

Answer this question