Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
0
but is there a way to change the text to countdown from 2 minutes? javlon123 0 — 9y
0
Yea, you can use a for loop and a wait(1) YellowoTide 1992 — 9y
Ad

Answer this question