Cooldown with text Popup (Please wait 5 seconds...)

Oh I thought you wanted it to countdown in negative digits. Then replace the loop with:

local x = 5
while x <= 5 do
    wait(1) -- oops forgot to add a wait
    [GUI].Text = "Cooldown ("..tostring(x)..")"
    x = x - 1
end

[GUI].Visible = false 

I might have made a mistake in the original code. Sorry!

2 Likes

Put it before the wait 5 and take it out after the wait 5

1 Like
local part = workspace.TeleportPart
local plr = game.Players.LocalPlayer

local textlabel = script.Parent.TextLabel
local x = 5

script.Parent.MouseButton1Click:Connect(function()
local humanoidrootpart = plr.Character:FindFirstChild(“HumanoidRootPart”)
if humanoidrootpart then
humanoidrootpart.CFrame = CFrame.new(part.CFrame.p) + Vector3.new(0,5,0)
local x = 5
while true do
    wait(1) -- oops forgot to add a wait
    textlabel.Text = "Cooldown ("..tostring(x)..")"
    x = x - 1
if x <= 0 then 
textlabel.Visible = false
break
end
end
end
end)

this should break the loop and set the textlabel’s visible to false once it hits 0, and of course add a debounce to the mousebutton1click because they could activate it again if the cooldown is on.

It would be more efficient to use <= like:

Why not use a for loop?

-- db = Debounce (start with: local db = true)
if db == false then return end
db = false
--start 5,end 0,count -1
for i = 5,0,-1 do -- i = current number
     textlabel.Text = "Please Wait " .. i  .. " seconds..." -- "Text" .. number .. "Text"
     task.wait(1) -- speed of the count
end 
-- continues when start = end
db = true
print("Done")
1 Like

Everyone here did this incorrectly lol.

Here’s a precise cooldown:

local timeleft = 5 --seconds
while timeleft > 0 do
timeleft -= task.wait(1)
textLabel.Text = "Please wait "..math.round(timeleft).." seconds..."
end
--the timer is done!

pop-up part:

local newPopup --replace with your new gui
local oldPopup --replace with your old gui
oldPopup:TweenPosition(Udim2.new(1, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1)
newPopup:TweenPosition(oldPopup.Position, Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1)
task.wait(1)
oldPopup:Destroy()

You can add these to your current code respectively.

Yeah you are kind of right because I tried all of those and it made not alot of sense.
I am going to try this right now!

I did it and this happened, its showing an error:

You didn’t specify them in your code yourself.

Yeah sorry I kind of did not understood how oldpopup and newpopup thing is going to work

1 Like

It’s the location of the new pop up. But it kind of sounds like your code didn’t make one.

1 Like

Hmm so what should I do? I am still a bit confused with that part. Will try without tween till you reply

1 Like

I’m confused as well. What is the pop up for your GUI?

1 Like

lets forget about tween part for now and can you help me with detecting 2 clicks?
like I want that pop up to happen after the user clicks the button more than once.

You can use Button.Activated (for your button) and the parameter tells us how many clicks it has:

button.Activated:Connect(function(_,clicks)
if clicks < 2 then
return
end
end)

You could do this
‘’‘Lua
Local Debounce = true
Button.Activated:Connect(function()
If Debounce == True then
–teleport the player
Wait(5)
Else
–open the wait 5 seconts thingy
‘’’

Hi there. You can copy and paste this and adjust it however you need to do so!

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local TeleportPoint = workspace.TeleportPart
local Client = Players.LocalPlayer
local Active = false
local ShouldCountDown = false
local TextLabel = script.Parent -- Change this to whatever you need.
local RunFunction

function Countdown(Time, Text)
	RunFunction = RunService.Heartbeat:Connect(function(DT)
		if ShouldCountDown == false then
			ShouldCountDown = true
			task.wait(1)
			Time -= 1
			ShouldCountDown = false
			if Time <= 0 then -- If there are any bugs that caused the countdown to go past 0 which means it'd be -1, then the code will stop instead of being permanently stopped because it hit -1.
				Active = false
				Text.TextTransparency = 1
				Text.TextStrokeTransparency = 1
				--	Text.BackgroundTransparency = 1 -- Remove the dashes that come before "Text.BackgroundTransparency" to make this transparent too.
				RunFunction:Disconnect() -- Disconnects the event so it will not continue running in the background.
			end
		end
	end)
end

local function TweenText(Text, TimeLeft)
	Text.Text = "Please wait "..tostring(TimeLeft).." seconds..."
	local Info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false) -- Change false to true if you'd like it to go away right after appearing.
	local Goal = {}
	Goal.TextTransparency = 0
	Goal.TextStrokeTransparency = 0
	--	Goal.BackgroundTransparency = 0 -- Remove the dashes that come before "Goal.BackgroundTransparency" to apply this to the goal.
	local Tween = TweenService:Create(Text, Info, Goal)
	Tween:Play()
	Tween.Completed:Connect(function()
		task.wait(0.5) -- Adding "TweenInfo.new(1)" with task.wait(4) = 5. Which means a five second wait. Remove this line if you want.
		Countdown(5) -- Starts the countdown function.
	end)
end

script.Parent.MouseButton1Click:Connect(function()
	if Active == false then
		Active = true
		if not game.Workspace:FindFirstChild(Client.Name) then
			return -- Stops the code from proceeding if the player's character does not exist.
		end
		local Info = TweenService
		local RootPart = Client.Character:FindFirstChild("HumanoidRootPart")
		if RootPart then
			RootPart.CFrame = CFrame.new(TeleportPoint.CFrame.Position + Vector3.new(0, 5, 0))
			TweenText(TextLabel)
		end
	end
end)
1 Like

Alright replace this with: – Trainmaster2341 had it right
– put a local on top (out of function)
local db = false

if db == false then
db = true
textlabel.Visible = true
for i = 5,0,-1 do
	textlabel.Text = "Please wait "..i.." seconds"
	task.wait(1)
	if i == 5 then
		textlabel.Visible = false
	end
end 
db = false
end

Mate this is insane script, not just you helped me but I got to learn alot of things as well. Thank you so much mate :))

And yeah theres a new post.
I really need help with Player Gui saving script > Save Gui (Button Color) & (Image)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.