Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make this into a gui that clicks then you wait 2 mins then u can click again?

I have a script it is supposed to refresh your character. I would like for it to be such as : "once u click the button it refreshes your character then it says a countdown from 2 minutes then after 2 mins is up you can use it again." heres the script so far:

plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	pcall(function()
		local Pos = plr.Character:GetPrimaryPartCFrame()
		plr:LoadCharacter()
		plr.Character:SetPrimaryPartCFrame(Pos)
		if plr.Character:FindFirstChild("ForceField") then
			plr.Character["ForceField"]:Destroy()
		end
	end)
end)

I don't know if this is possible I tried so many things such as adding more functions but couldn't get it to work.

1 answer

You will want to use a debounce for this. Using a debounce allows you to make something not run until you want it too

plr = game.Players.LocalPlayer

local debounce = false
script.Parent.MouseButton1Click:connect(function()
	pcall(function()
		if debounce == false then
			debounce = true --set it to true so the condition wont pass
			local Pos = plr.Character:GetPrimaryPartCFrame()
			plr:LoadCharacter()
			plr.Character:SetPrimaryPartCFrame(Pos)
			if plr.Character:FindFirstChild("ForceField") then
				plr.Character["ForceField"]:Destroy()
			end
			wait(60 * 2) --waits two minutes
			debounce = false --allows the function to run again
		end
	end)
end)

2 comments

0

but is there a way to change the text to countdown from 2 minutes?

0

Yea, you can use a for loop and a wait(1)

This discussion is preserved as it was. New answers, comments, and votes are closed.