I need your feedback or help on how to stop remote spam in this script

Hello, I am a beginner developer. As you can see, this is SimulateBulletScript from the fe gun kit’s scripts. I met an exploiter that spam the remote of the fe gun kit during the game, causing the game and server to crash. I tried to make the remote unspam to stop the exploiter, but failed. I am wondering how to effectively anti-spam in this script. Any help would be appreciated.
Because of that exploiter, the number of players in my game has decreased from 80 to 20-30 :<

VisualizeHitEffect.OnServerEvent:Connect(function(Player, Type, Replicate, Hit, Position, Normal, Material, ...)
	local Table = {...}
	if Type == "Normal" then
		for _, plr in next, Players:GetPlayers() do
			if plr ~= Player then
				VisualizeHitEffect:FireClient(plr, Type, Replicate, Hit, Position, Normal, Material, Table[1], Table[2], Table[3], nil)
			end
		end
	elseif Type == "Blood" then
		for _, plr in next, Players:GetPlayers() do
			if plr ~= Player then
				VisualizeHitEffect:FireClient(plr, Type, Replicate, Hit, Position, Normal, Material, Table[1], Table[2], nil)
			end
		end
	end
end)

VisualizeBullet.OnServerEvent:Connect(function(Player, Module, Tool, Handle, VMHandle, CLDirections, SVDirections, FirePointObject, HitEffectData, BloodEffectData, BulletHoleData, ExplosiveData, BulletData, WhizData, ClientData)
	SecureSettings(Player, Tool, Module)	
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			VisualizeBullet:FireClient(plr, Module, Tool, Handle, VMHandle, CLDirections, SVDirections, FirePointObject, HitEffectData, BloodEffectData, BulletHoleData, ExplosiveData, BulletData, WhizData, ClientData)
		end
	end
end)

VisualizeMuzzle.OnServerEvent:Connect(function(Player, Handle, VMHandle, MuzzleFlashEnabled, MuzzleLightData, MuzzleEffect, Replicate)
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			VisualizeMuzzle:FireClient(plr, Handle, VMHandle, MuzzleFlashEnabled, MuzzleLightData, MuzzleEffect, Replicate)
		end
	end
end)

PlayAudio.OnServerEvent:Connect(function(Player, Audio, LowAmmoAudio, Replicate)
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			PlayAudio:FireClient(plr, Audio, LowAmmoAudio, Replicate)
		end
	end
end)

ShatterGlass.OnServerEvent:Connect(function(Player, Hit, Pos, Dir)
	if Hit then
		if Hit.Name == "_glass" then
			if Hit.Transparency ~= 1 then
				if PhysicEffect then
					local Sound = Instance.new("Sound")
					Sound.SoundId = "http://roblox.com/asset/?id=2978605361"
					Sound.TimePosition = .1
					Sound.Volume = 1
					Sound.Parent = Hit
					Sound:Play()
					Sound.Ended:Connect(function()
						Sound:Destroy()
			        end)
					GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
					--[[local LifeTime = 5
					local FadeTime = 1
					local SX, SY, SZ = Hit.Size.X, Hit.Size.Y, Hit.Size.Z
					for X = 1, 4 do
						for Y = 1, 4 do
							local Part = Hit:Clone()
							local position = Vector3.new(X - 2.1, Y - 2.1, 0) * Vector3.new(SX / 4, SY / 4, SZ)
							local currentTransparency = Part.Transparency
							Part.Name = "_shatter"
							Part.Size = Vector3.new(SX / 4, SY / 4, SZ)
							Part.CFrame = Hit.CFrame * (CFrame.new(Part.Size / 8) - Hit.Size / 8 + position)			
							Part.Velocity = Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
							Part.Parent = workspace
							--Debris:AddItem(Part, 10)
							task.delay(LifeTime, function()
								if Part.Parent ~= nil then
									if LifeTime > 0 then
										local t0 = os.clock()
										while true do
											local Alpha = math.min((os.clock() - t0) / FadeTime, 1)
											Part.Transparency = Math.Lerp(currentTransparency, 1, Alpha)
							    			if Alpha == 1 then break end
						      				task.wait()
										end
										Part:Destroy()
									else
										Part:Destroy()
					    			end
								end
							end)
							Part.Anchored = false
						end
					end]]
				else
					local Sound = Instance.new("Sound")
					Sound.SoundId = "http://roblox.com/asset/?id=2978605361"
					Sound.TimePosition = .1
					Sound.Volume = 1
					Sound.Parent = Hit
					Sound:Play()
					Sound.Ended:Connect(function()
						Sound:Destroy()
			        end)
					local Particle = script.Shatter:Clone()
					Particle.Color = ColorSequence.new(Hit.Color)
					Particle.Transparency = NumberSequence.new{
						NumberSequenceKeypoint.new(0, Hit.Transparency), --(time, value)
						NumberSequenceKeypoint.new(1, 1)
					}
					Particle.Parent = Hit
					task.delay(0.01, function()
						Particle:Emit(10 * math.abs(Hit.Size.magnitude))
						Debris:AddItem(Particle, Particle.Lifetime.Max)
					end)
					Hit.CanCollide = false
					Hit.Transparency = 1
				end
			end
		else
			error("Hit part's name must be '_glass'.")
		end
	else
		error("Hit part doesn't exist.")
	end
end)

Maybe add a debounce somewhere.

Or in the OnServerEvent , add a parameter at the back, for example AntiHacker .
In your local script, set that parameter value to a code, for example "dQw4w9WgXcQ".

Then in this script, do

if AntiHacker ~= "dQw4w9WgXcQ" then
    player:Kick("Nice try firing remote events bro")
end

Exploiters are able to fire remote events with a LocalScript.
So in their local script they’ll do

RemoteEvent:FireServer()

But if they don’t have that parameter at the back, they’ll just get kicked lol

You may even want to make a script that generates random codes because some hackers can read scripts. But most hackers don’t code and probably only know how to fire remote events

1 Like

Hey. It is best you add debounces to server events! How can you do this? Check below!
What does this do?
It delays the requests from clients so they cannot spam the remote.

local debounce = false
local Remote = pathwayhere:WaitForChild("eventname")

Remote.OnServerEvent:Connect(function()
if debounce == true then return end
debounce = true
-- Code
wait(.1)
debounce = false
end)
1 Like

I suggest putting the debounce in the local script instead so the remote event won’t fire continously. Your current script will make the remote event keep firing but it just won’t execute the main script

1 Like

Have debounce on the client and on the server.

In the server script have a table for debounce and insert their name into the table so the debounce can go for multiple players, ex:

(this isnt tested)

local playerDebounceTable = {}

event.OnServerEvent:Connect(function(player)

if playerDebounceTable[player.Name] then
return
end
playerDebounceTable[player.Name] = true
--whatever
task.wait(5)
playerDebounceTable[player.Name] = nil

end)
1 Like

Not a good idea. Regardless if its in the local script, exploiters can still fire the remote and bypass the debounce that way. This is why the debounce in the server is better. If you don’t wish to use a debounce variable, use bool values to check if the individuals players bool value is true or false and change accordingly.

1 Like

The remote firing itself can also cause lag too am i right? Running the code whether or not the remote hasnt fired in a specific time isnt really efficient enough