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

My debounce is not working with a "Touched function", what is wrong? (SOLVED)

Hey, This script works fine, the only thing that does not work is the debounce, what is wrong?

The "dead" part should damage the player after the part have blinked and then just be a normal part again after 5 sec. But now it damage the player all the time, help.

while true do
wait(5)
debounce = false

script.Parent.Transparency = 1
wait(1)
script.Parent.Transparency = 0
wait(1)
script.Parent.Transparency = 1
wait(1)
script.Parent.Transparency = 0
wait(1)

debounce = true

if debounce == true then

script.Parent.Touched:Connect(function(hit)
				
				local humanoid = hit.parent:FindFirstChild("Humanoid")
				if humanoid then
				humanoid.Health = humanoid.Health -1
				end
				
			end)
			end

end

Thanks!

1 comment

0

"Touched" is an event, not a function. Also, it's never advisable to have an event listener in an infinite loop unless you are disconnecting it.

1 answer

Try to define the debounce outside the function so

local debounce = false -- or true

while true do
wait(5)
debounce = false

script.Parent.Transparency = 1
wait(1)
script.Parent.Transparency = 0
wait(1)
script.Parent.Transparency = 1
wait(1)
script.Parent.Transparency = 0
wait(1)

debounce = true

if debounce == true then

script.Parent.Touched:Connect(function(hit)

                	local humanoid = hit.parent:FindFirstChild("Humanoid")
                	if humanoid then
                		humanoid.Health = humanoid.Health -1
                	end

            	end)
            end

	end
end

4 comments

0

that might work and it might not

0

This will not work as intended.

0

It does not work

0

I fixed it

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