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

How would I make a cooldown for a TextButton?

So I wanna award someone 1 skill every time they press a TextButton. How would this work? Here is my script

game.Players:WaitForChild(game.Players.LocalPlayer, 10)
--References
local player = game.Players.LocalPlayer
local mSkill = player.leaderstats.Skill
local rebirths = player.leaderstats.Rebirths 
local button = player.PlayerGui.Button.Music
--Values
local mSkillAdd = 1
--ClickScript
button.MouseButton1Click:Connect(function()
	if rebirths.Value == 0 then
		mSkill.Value = mSkill.Value + 1
		print(mSkill.Value)
		wait(1)
	end
end)

1 answer

✓ Accepted answer

Hey Dak,

Just use a debounce and toggle it like you would a normal cooldown effect.

####Like This

game.Players:WaitForChild(game.Players.LocalPlayer, 10)
--References
local player = game.Players.LocalPlayer
local mSkill = player.leaderstats.Skill
local rebirths = player.leaderstats.Rebirths 
local button = player.PlayerGui.Button.Music
local deb = false; -- Closed door is open to begin with.
--Values
local mSkillAdd = 1
--ClickScript
button.MouseButton1Click:Connect(function()
    if deb then return end; -- If closed door(If door is closed)
    if rebirths.Value == 0 then
    	deb = true; -- Closed door is set to true(Closing the door)
        mSkill.Value = mSkill.Value + 1
        print(mSkill.Value)
        wait(1)
	deb = false; --Makes closed door false.(Opening the door)
    end
end)

###Debounce cooldown effects can be best thought of as a door. Once the script has started running you wanna close the door. Then, after a certain time open the door so that the script can run again. Think of deb in the above script as a closed door.

##Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

Idealist Developer

1 comment

0

Thank you I'm new and have not learned about Debouces

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