Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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


2 comments

0

line 6, make it game.Workspace instead of game.workspace

0

yeah that doesn't help

1 answer

✓ Accepted answer

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

2 comments

1

pov: people dont understand the meaning of 'scope' :pensive:

0

just search up debounce tutorial, and he'll have the answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.