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

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

Asked by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 2 years ago

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.

0
Sorry that the GIF was abit of lagging. Xapelize 2658 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years 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 2658 — 4y
Ad

Answer this question