Hey, I need help adding debounce to this script, so everytime you click the TextButton, it leaves you with a countdown from 5 to 0 seconds, until you can click it again. It then returns to the normal text, β Gamble β.
The textbutton in here is already set as a variable, and itβs called TextButton
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local coins = game.Players.LocalPlayer.leaderstats.Scamollars
local coinsn = game.Players.LocalPlayer.leaderstats.Scamollars.Value
local randomnumber = math.random(1, 3)
local eventwin = game.ReplicatedStorage.Gamble.GambleWin
local eventlost = game.ReplicatedStorage.Gamble.GambleLost
local plr = game.Players.LocalPlayer
local TextButton = script.Parent.Parent.TextButton ------------ DEVFORUM SUPPORT
local EnterAmount = script.Parent.Parent.TextBox
local EnterAmountTxt = script.Parent.Parent.TextBox.Text
local Coins = game.Players.LocalPlayer.leaderstats.Scamollars
local str = EnterAmountTxt
local num = tonumber(str)
print(num)
local str1 = coinsn
local coinnum = tonumber(str1)
print(coinnum)
if num <= 0 then
script.Parent.Loss:Play()
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(1, 0, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "β Insert a value, higher than 1+!"
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
return end
if num == nil then
script.Parent.Loss:Play()
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(1, 0, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "β Enter an amount!"
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
return end
if num > coinnum then
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(1, 0, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "β You don't have that much coins!"
script.Parent.Loss:Play()
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
return
else
--Put here what will happen if they have enough.
print("ENOUGH COINS.")
if coins.Value <= 0 then
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(1, 0, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "β Not enough coins!"
script.Parent.Loss:Play()
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
return end
print(randomnumber)
if randomnumber == 1 then
print("You've won!")
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(0.333333, 1, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "π You've won!"
script.Parent.Win:Play()
local str = EnterAmountTxt
local num = tonumber(str)
print(num)
eventwin:FireServer(plr, num)
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
else
print("You've lost!")
script.Parent.Parent.Parent.Menu.Status.TextColor3 = Color3.new(1, 0, 0)
script.Parent.Parent.Parent.Menu.Status.Text = "β You've lost!"
script.Parent.Loss:Play()
eventlost:FireServer(plr, num)
wait(5)
script.Parent.Parent.Parent.Menu.Status.Text = ""
end
end
end)