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

Why does the output keeps on printing even I put debounce?

Please note this is a old post, so the time when I posted this I was a young kid and a noob, please don't complain

GIF preview are not public due to private issues.

local part = script.Parent
local ceiling = workspace.ce
debounce = false


function ontouched()
	debounce = true
	ceiling.Transparency = 1
	debounce = false
end

function touchedended()
	debounce = true
	ceiling.Transparency = 0 
	debounce = false
end

script.Parent.Touched:Connect(function(ontouched)
	print("Touching")
end)

script.Parent.TouchEnded:Connect(function(touchedended)
	print("Touch Ended")
end)

Does anything blocks the debounce to work?

There no error at all, every help is appreciated.

1 comment

0

Sorry that the GIF was abit of lagging.

1 answer

✓ Accepted answer

So the problem is that you're printing ("Touching") or ("Touch Ended") for each touch, not connecting to the actual function. You're also not waiting between them and instantly setting the debounce to true/false.

To fix it:

  1. Delete the lines that say print() and end).

  2. Have a wait between setting debounce and have a check for the debounce.

Fixed script:

local part = script.Parent
local ceiling = workspace.ce
debounce = false
local waitTime1 = 3; -- Time to wait on the onTouched before resetting debounce.
local waitTime2 = 3; -- Time to wait on the TouchEnded function before resetting debounce.


function ontouched()
   if debounce then return end; -- If debounce is true, then stop here, else, continue.
    debounce = true
    ceiling.Transparency = 1
    wait(waitTime1);
    debounce = false
end

function touchedended()
   if debounce then return end; -- If debounce is true, then stop here. Else, continue.
    debounce = true
    ceiling.Transparency = 0
    wait(waitTime2); 
    debounce = false
end

script.Parent.Touched:Connect(function(ontouched);

script.Parent.TouchEnded:Connect(function(touchedended);

Please accept as answer if this worked for you.

1 comment

0

This is working... Im so stupid XDDDD

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