Ad
Log in to vote
0

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

Asked by
Xapelize 1080 Moderation Voter
1 year ago
Edited 13 days ago

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.

0
Sorry that the GIF was abit of lagging. Xapelize 1080 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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.

0
This is working... Im so stupid XDDDD Xapelize 1080 — 1y
Ad

Answer this question