Bit of a weird question but would it be possible for 2 events like this to be received by the server with a time of less than 5 seconds on the server side :
The reason I ask this is because I am thinking of having an anti cheat system like this to prevent players from firing the two effects too quickly one after the other on the server side :
game.ReplicatedStorage.RemoteEvent1.OnServerEvent:Connect(function(plr)
local StartTime = tick()
game.ReplicatedStorage.RemoteEvent2.OnServerEvent:Connect(function(plr)
local timeDiff = tick() - StartTime --Time difference between when event was received and event 2 was received
if timeDiff < 5 then
plr:Kick("Second Event fired too quickly")
end
end)
end)
This seems to be a very good way from my perspective but I am worried that if the player is on very high ping during the first events firing then their ping drops a lot when the second event fires, the second event will arrive sooner than expected due to the original event being delayed. So it is important for me to know if the firing of an event can speed up mid way through its travel to the server or not. I don’t want people being kicked just for having unstable internet.
Do you think it would be reliable to send the ping of the player during the first event in the parameters of the second event and adding the time to the delta to account for ping or is it too risky? Because you see I need the second event to give me the players mouse position after the first event is fired and I don’t see any other way to make this less exploitable. Something like this :
game.ReplicatedStorage.RemoteEvent1.OnServerEvent:Connect(function(plr)
local StartTime = tick()
game.ReplicatedStorage.RemoteEvent2.OnServerEvent:Connect(function(plr,ping) --Gives ping when first event was fired
local timeDiff = tick() - StartTime + ping --Time difference between when event was received and event 2 was received
if timeDiff < 5 then
plr:Kick("Second Event fired too quickly")
end
end)
end)
I could ensure the ping the client sends is not a negative number to make the tampering of the ping not useful to them since making the ping higher will just result in a kick anyway?
The client can send any value as their ping. If you kick them for taking too long to respond then you will also kick regular players who just have high ping. There are no ways around it.
But is that relavent since they will get kicked for responding too quickly not for taking to long and since ping can only be a possitive number in reality, adding any amount of ping to the delta wont result in a kick, only subtracting
Edit: I am dumb , just realsied what i said XD
I strongly recommend reading the Exploiting Explained thread. Specifically the part about communication with the client. This thread will tell you everything you need to know. Good luck!
Sorry again this is just an interesting topic, but I just realised , since the ping can be tempered with, why not just get the ping on the server side by doing Player:GetNetworkPing() like I have done here
I just went back to the top of the thread and reread what your goal is.
If you don’t want something like a bullet to be fired more than once per second then what you do is you track the time on the server. Not the time between events.
We have been talking about the wrong thing this whole time.
But it’s my fault because I didn’t read your whole original post carefully to see what you were trying to accomplish and immediately just answered the question in the topic subject.
A basic setup looks like this:
local debounces = {}
remoteEvent.OnServerEvent:Connect(function(player)
if not debounces[player] then
debounces[player] = true
----
-- Action code here
----
task.wait(1)
debounce[player] = false
end
end)
This is a basic debounce which ensures that only one “action” will run per second no matter how many times the remote is fired. It doesn’t require knowing the clients ping. The server doesn’t really care when or how many times the client fires the event, it will only run the function once per second.
Sorry for going down the rabbit hole and ping, this is the answer you were looking for.
Oh but how should I get the new mouse.Hit value in this case? Because I want the player to be able to aim at the end of the throwing animation, not the start.
Send Mouse.Hit as a parameter in the RemoteEvent. Only fire the Remote at the end of the throwing animation. You don’t need to tell the server when the animations starts.