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

People keep spamming rebirth button?

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

2 comments

0

paste the script in the question

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.

2 answers

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

4 comments

0

I dont think terrain accepts a string value

0

what does terrain have to do with this

0

Look at lines 8 and 10.

0

????

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)

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