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

How would I go about a debounce on the server side using Remote Events?

So I made a tool where it spawns a brick but since I don't want people to spam it I wanted to put a debounce

I decided not to do it in the local script because if I did that exploiters can easily exploit it

So heres my Local Script


local Tool = script.Parent
local Handle  = Tool.Handle
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

Tool.Equipped:Connect(function(Mouse)
	
	Mouse.Button1Down:Connect(function()-- If Mouse is pressed
		RemoteEvent:FireServer() -- I fire Server
	end)

end)

and my Server Script

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

local CanFire = true

local ReloadTime = 999

RemoteEvent.OnServerEvent:Connect(function(player)

if CanFire == true then
	local part = Instance.new("Part")
	part.Parent = workspace
		CanFire = false
		wait(ReloadTime)
		CanFire = true
	
	
	end
	


end)

The problem is that if one person fires this remote the other person cannot fire the remote and has to wait 999 seconds before firing again

I want it that each person can fire it without affecting other people

like Filtering Enabled

2 comments

0

I answered a question very similar to this yesterday. Look at my answer and the comment, because the comment mentions some things that should be changed. https://scriptinghelpers.org/questions/85830/how-do-i-make-my-debounce-for-remote-event-for-each-player-not-just-for-everyone

0

2 days ago I mean.

2 answers

You can use a cool down time. This may be different than what you mean!

wait(5) --Waits 5 seconds

2 comments

0

Put it at the end of your script!

0

PUT EVERYTHING AFTER THE COOLDOWN TIMER BELOW IT

I personally solve this issue by using a table debounce for each player's userid, let me know if you have any questions:

local CooldownTimer=5

local OnCooldown={}
local function Cooldown(UserId)
	OnCooldown[#OnCooldown+1]=UserId
	spawn(function()
		wait(CooldownTimer)
		for I=1,#OnCooldown do
			local CooldownedPlayer=OnCooldown[I]
			print(CooldownedPlayer)
			if CooldownedPlayer==UserId then
				table.remove(OnCooldown,I)
			end
		end
	end)
end
local function CheckIfOnCooldown(Player)
	local Passed=false
	for I=1,#OnCooldown do
		local CooldownedPlayer=OnCooldown[I]
		print(CooldownedPlayer)
		if CooldownedPlayer==Player.UserId then
			Passed=true
		end
	end
	return Passed
end

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