Hello Roblox Developer Community! I’ve got quite a tricky problem and I am hoping some of you can find a solution. You see, I’m trying to make teleport buttons. However I want to make it so theres a cooldown before pressing it again. How would I also make it so you can’t press every button until the cooldown is over. Let me know how I would be able to solve this. Thank you!
This is actually a pretty simple problem, try:
local debounce = false
local cooldown = 1 -- How long you want the cooldown to be
local function teleport()
if debounce = false then
debounce = true -- Any other attempts will be canceled with the line of code above until debounce = false
-- Do your teleport stuff here
task.wait(cooldown) -- Waiting until cooldown is complete until allowing more teleport requests
debounce = false
end
end)
-- Here you could call the function like "button.touched:Connect(teleport())" or something
By the way “debounce” is what people use to say they don’t want multiple requests in a period of time and is the standard term.
same code basically …
local db=true
function teleport()
if db then db=false
--teleport
task.wait(3)
db=true
end
end
if they are going to a different game the wait could be 6
And here is a link to an open source teleport that is a bit more fancy.
^-- this is a test program for passing gear. Just look at the teleport parts.
You said “Debounce that applies to all buttons”… Just use this technique for each button.
Hey Developer! Here’s a code that could help you, if you have any issues with the code let me know:)
local teleportButton = script.Parent
local cooldownTime = 10
local isCooldown = false
local function teleportPlayer()
if not isCooldown then
-- Perform teleportation logic here
-- Start cooldown
isCooldown = true
for time = cooldownTime, 1, -1 do
-- Update cooldown timer UI label
teleportButton.TextLabel.Text = tostring(time)
wait(1)
end
teleportButton.TextLabel.Text = "Teleport" -- Reset UI label
isCooldown = false -- Cooldown is over, allow button press again
end
end
teleportButton.MouseButton1Click:Connect(teleportPlayer)
Debounce is a technique the actual variable is being used as a flag.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.