#how to make a touch with debounce time

1 messages · Page 1 of 1 (latest)

meager elbow
#

can anyone help me on how to make it so that when my buttonmodel is touched it does the code and has a debounce time of 10 seconds

#

local buttonmodel = script.Parent
local s1 = math.random(6, 7)
local s2 = math.random(6, 7)
local s3 = math.random(6, 7)

local function roll()
print(s1)
task.wait(1)
print(s2)
task.wait(1)
print(s3)

if s1 == 7 and s2 == 7 and s3 == 7 or s1 == 6 and s2 == 6 and s3 == 6  then
    print("YOU WON THE JACKPOT!!!")
end

end
roll()

whole fable
#

Yes

#

local buttonmodel = script.Parent
local debounce = false
local debounceTime = 10

-- function to roll
local function roll()
    local s1 = math.random(6, 7)
    local s2 = math.random(6, 7)
    local s3 = math.random(6, 7)

    print(s1)
    task.wait(1)
    print(s2)
    task.wait(1)
    print(s3)

    if (s1 == 7 and s2 == 7 and s3 == 7) or (s1 == 6 and s2 == 6 and s3 == 6) then
        print("YOU WON THE JACKPOT!!!")
    end
end

-- trigger on touch with debounce
buttonmodel.Touched:Connect(function(hit)
    if debounce then return end  -- if debounce is active, ignore
    debounce = true

    roll()

    task.delay(debounceTime, function()
        debounce = false
    end)
end)

meager elbow
#

ohhh

#

can u explain to me so i know how

whole fable
#

U define denounce as true or false so you can just do a simple check to see if it’s false yk

#

Then u define the denounce time because that’s how long you want to wait

#

Then make a touched event for the model so we know when it’s touched

#

Then check if debounce is true, if it is that means we still on cd

#

Otherwise turn debounce on and start the function then wait the debounce time

#

And then turn it off after that time

meager elbow
#

ohh