Let’s take this simple gui teleport script as an example
local part = workspace.TeleportPart
local plr = game.Players.LocalPlayer
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)
end
end)
===========================
What do I want it to do?
– I want it to have a cooldown of 5 seconds.
– I want it to be connected with textlable saying " Please wait 5 seconds… "
=========================== – I can add variables to get the Textlabel I want and connect it with code. – I can make it pop up using Tween service.
The things I need help with is:
– I need a code which makes 5 seconds cooldown function
– I need a code which changes text according to the time remaining.
– I want the new text pop up to push the old pop up above and not overlap each other.
===========================
I am active here for next few hours, will be waiting patiently and will reply fast :))
You could do this
LuaScript–
Local Start = true
–Add a function here
If Start == true then
Start = false
–wait 5 seconts pop up
Script here
Wait(5)
Start = true
end
end)
replace the “Cooldown (”…tostring(x)…“)” with this: textLabel.Text = "Please wait "..tostring(x).." seconds"
If you want it the label to stay at “Please wait 5 seconds”, replace the code I gave you with this:
textLabel.Text = "Please wait 5 seconds"
wait(5)
-- anything else you want to do goes here like closing the GUI etc.
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.
-- 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")
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.