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

People keep spamming rebirth button?

Asked by 5 years ago

Ok so basically I have this gui where when you get a certain amount of points, you get to rebirth. But somehow, people spam the rebirth button and they get extra rebirths, when they are only supposed to get one. Can anyone help?

Here is a link to a picture of the script: https://gyazo.com/917c67e62665bc4c2b3d2370560f1175

0
paste the script in the question DinozCreates 1070 — 5y
0
You're going about this the wrong way. You should be using a changed event instead of an infinite loop. Roblox has provided some extremely efficient (or at least more efficient than what you are doing) and easy to use methods for its developers. Don't waste them. User#25115 0 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This should work, if you don't want players spamming the rebirth button you need to use debounce

Change local timedelay = 2 to whatever number you want (in seconds)

Also use while true do because while wait() do is bad practice

Link to debounce

I have not tested this yet so it maaaay not work but chances of that are slim
local plr = game.Players.LocalPlayer
local debounce = true
local timedelay = 2
while true do
    if debounce == true then
        debounce = false
        if (plr.leaderstats.Rebirths.Value * 350) + 350 <= plr.leaderstats.Points.Value then
            script.Parent.Terrain = "Click to Rebirth"
        else
            script.Parent.Terrain = "Rebirth in " ..(plr.leaderstats.Rebirths.Value * 350) + 350 - plr.leaderstats.Points.Value
        end
        wait(timedelay)
        debounce = true
    end
end
0
I dont think terrain accepts a string value theking48989987 2147 — 5y
0
what does terrain have to do with this LoganboyInCO 150 — 5y
0
Look at lines 8 and 10. User#20279 0 — 5y
0
???? LoganboyInCO 150 — 5y
Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
5 years ago

You can add a debounce to prevent spamming the function

local Server = game:GetService("Players")
local Player = Server.LocalPlayer

local debounce = false

script.Parent.MouseButton1Click:Connect(function()

    if debounce then return end ---If debounce = true, then stop progression
    debounce = true ---Sets debounce to true after clicking the button. Prevents spamming.
    script.Parent.RebirthEvent:FireServer()

    wait(5) ---Amount of time to wait before they can click the button again.
    debounce = false ---Sets debounce to false, allowing the code to run again.



end)

Answer this question