How can I check whether the remote event was fired back to the server

Hi everyone, I’m currently making an anti-exploit, and I want to verify whether the humanoid is walking before I kick the player.

How can I make it so, if the remote event wasn’t fired back to the server, still kick the player?

To be simple, my question is on how I can kick the player even though the remote event wasn’t fired back?

This is relatively simple and would be scripted as so:

  • Fire the event to the client

  • Insert a table that stores the time that the event was fired, the player that it was fired to, and a value that says if they have responded or not in a table

  • Have a loop of some sort that runs every second or every frame that loops through the table with all of the events to see if they have responded in the amount of time allotted

  • If not, kick them

  • If they have, remove the data table from the main table

  • You also need to make sure to get the data table from the player firing to the server to make sure that you actually set when the server recieves a response

I’m using two seperate remote events. Basically, I make a boolean value and loop it around every time to see whether it’s fired back? Would that have a performance difference and affect the player experience?

You can use two separate remote events yes.

The information you are passing here is only passed once, so the impact on the network is literally only a few bytes of data (aka nearly 0).

How should I implement the table into my current script? My functions are dependent on the remote event, and the player joined event (which isn’t considered in this issue).

For the remote event, I’m assuming that I create a table outside of the function, since that function solely depends on the remote event. What’s the best way to put the table?

Your code would look something like this:

Server

local RunService = game:GetService("RunService")
local network = game.ReplicatedStorage.Network
local network_cache = {}

RunService.Heartbeat:Connect(function(dt)
    for player, data in pairs(network_cache) do
        if tick() > data.expiration and not data.responded then
            network_cache[player] = nil
            player:Kick("Didn't respond in time.")
        elseif tick() > data.expiration and data.responded then
            network_cache[player] = nil
        end
    end
end)

local function verify_player_response(player)
    local data = {
        player = player,
        expiration = tick() + 5, -- expires if they don't respond in 5 seconds
        responded = false
    }
    network_cache[player] = data
    network:FireClient(player)
end

network.OnServerEvent:Connect(function(player)
    if network_cache[player] then
        network_cache[player].responded = true
    end
end)

Client

local network = game.ReplicatedStorage.Network
network.OnClientEvent:Connect(function()
    network:FireServer()
end)

(untested)

The only thing I would add to this would be to remove the player from the cache if they leave the game, but you should be able to figure out how to do that relatively easily.

2 Likes

Thanks, I’ll test it out right now.