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

Making a player unable to spam a remote event?

Asked by
OBenjOne 190
5 years ago

Like the question said I need to stop individual players from spamming a remote event I have. The tricky part is that I need to do this from server side after receiving the remote event. This is because for one thing I have heard that the more you regulate from server the more secure your game will be, and for another, I don't even understand most of my client side code because I did the one thing every developer is terrified to admit... I copied from the toolbox D: please don't mark my question as not constructive because it involves such code because I only need you to help with the server side which I wrote myself.

Server:

 local ReplicatedStorage = game:GetService("ReplicatedStorage")
 local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
 createPartEvent.Name = "CreatePartEvent"

 local function onCreatePartFired(player,transparency,velocity,position)
print(player.Name, "wants to fire this event"
 --here's where I need to put the restrictions for spamming I only want it to be fired once per second per player 
local Bullet = script.bullet:Clone()
    Bullet.Transparency = transparency 
    Bullet.Velocity = velocity 
    Bullet.Position = Position 
 end

 createPartEvent.OnServerEvent:Connect(onCreatePartFired)

Things I have considered for the anti spam:

  -- at the top of the script put 
 Fireable = true 
 --at the middle put
 If Fireable then
 Fireable = false
 --at the end
 wait (1) Fireable = true

Unfortunately this would make it so that player a could not fire if player b had just fired, not exactly what I want

Another idea: I could try to add an object value into the script that has the player as it's value whenever a player fired then use

 GetChildren() 

To see if the player had fired, and delete the value after one second but that sounds really confusing to me.

IMPORTANT: I didn't add the client side script to my code because I know it works and it is about 100 - 200 lines, plus I didn't write it. I can add it tonight if you really need it.

Even if you don't know the answer ideas would be very helpful too.

Ps. I wanted to use this space to apologize for some things I have been saying because I didn't take the time to read the full answer. Also to Incapaz because I got kind of mad at him for being so firm on not calling server scripts normal scripts and always pointing out decrepit code. He was right.

Anyways thanks for any help on my question!

(This was written on an iPhone so don't be surprised if I messed up on my script)

0
Use a debounce MaxDev_BE 55 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

The best way would be to use a debounce on the client side. I highly suggest doing this rather then doing it via server side as it is much more complicated and does not provide any benefits over doing it via client side. You should be able to understand all of your code.

0
OK I guess I'll just have to do it that way OBenjOne 190 — 5y
0
I just wanted to be lazy and not have to read through the code OBenjOne 190 — 5y
0
... OBenjOne 190 — 5y
Ad

Answer this question