You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
So i wanna do click delay for generator button
What is the issue? Include screenshots / videos if possible!
issue is - when i click button, button text become time which player need to wait, but when i click the button, my delay is 2 seconds, text just stop on 1.9 and don’t go lower each 0.1s. here is screenshot:
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tryed to make debug thing, but that didn’t help
My code:
local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local GuiService = Player.PlayerGui
local GameGUI = GuiService.GameGUI
local RNGBar = GameGUI.GameFrame.PlayableFrame.RNGBar
local RNGProgress = RNGBar.RNGP
local RNGBarFiller = RNGBar.Filler
local RNGClicker = script.Parent
local RNGMultiValue = script.Parent.RNGMulti
local RNGNumber = 0
local ClickWait = 0
local DB = 2
RNGClicker.MouseButton1Click:Connect(function()
RNGNumber = math.random(1,10)
RNGProgress.Text = RNGNumber
ClickWait = 2
while wait() do
DB = DB - 0.1
RNGClicker.Text = ClickWait - 0.1
wait(0.1)
end
end)
I think you should’ve add while wait() do out of MouseButton1Click
Only because i think what the loop repeats with Click, make a thing like this:
local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local GuiService = Player.PlayerGui
local GameGUI = GuiService.GameGUI
local RNGBar = GameGUI.GameFrame.PlayableFrame.RNGBar
local RNGProgress = RNGBar.RNGP
local RNGBarFiller = RNGBar.Filler
local RNGClicker = script.Parent
local RNGMultiValue = script.Parent.RNGMulti
local RNGNumber = 0
local ClickWait = 0
local DB = 2
RNGClicker.MouseButton1Click:Connect(function()
RNGNumber = math.random(1,10)
RNGProgress.Text = RNGNumber
ClickWait = 2
end)
while wait(0.1) do
DB = DB - 0.1
RNGClicker.Text = ClickWait - 0.1
end
local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local GuiService = Player.PlayerGui
local GameGUI = GuiService.GameGUI
local RNGBar = GameGUI.GameFrame.PlayableFrame.RNGBar
local RNGProgress = RNGBar.RNGP
local RNGBarFiller = RNGBar.Filler
local RNGClicker = script.Parent
local RNGMultiValue = script.Parent.RNGMulti
local RNGNumber = 0
local ClickWait = 0
local DB = 2
local canclick = 0 --might aswell replace with true or false.
local function count() --countdown function
while wait() do
if DB ~= 0 then
DB = DB - 0.1
RNGClicker.Text = ClickWait - 0.1
wait(0.1)
else
break
end
end
end
RNGClicker.MouseButton1Click:Connect(function()
if canclick == 0 then --if the player hasnt recently clicked
canclick = 1 --the player cant click anymore
RNGNumber = math.random(1,10)
RNGProgress.Text = RNGNumber
ClickWait = 2
count()
canclick = 0 --after the function finishes the player is able to click again.
end
end)
Sorry if there’s a dumb mistake in it I didnt test, but it should work!
local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local GuiService = Player.PlayerGui
local GameGUI = GuiService.GameGUI
local RNGBar = GameGUI.GameFrame.PlayableFrame.RNGBar
local RNGProgress = RNGBar.RNGP
local RNGBarFiller = RNGBar.Filler
local RNGClicker = script.Parent
local RNGMultiValue = script.Parent.RNGMulti
local RNGNumber = 0
local ClickWait = 0
RNGClicker.MouseButton1Click:Connect(function()
RNGNumber = math.random(1,10)
RNGProgress.Text = RNGNumber
ClickWait = 2
repeat
ClickWait -= 0.1
RNGClicker.Text = ClickWait - 0.1
wait(0.1)
until ClickWait <= 0
ClickWait = 0
end)
You weren’t changing the value of “ClickWait” so it was always “1.9” after 0.1 was subtracted from 2, you also didn’t have a break condition (an end point for the loop) I’ve fixed both of the issues in the above.