Detect if a RemoteEvent is sent in an interval of time on the server

Hi, I’m making a sprint script. You have stamina, which goes down by 1 every 1/10th a second when you sprint. Simple enough. FE, of course.

When sprinting (hold Left Shift) your walkspeed raises by +16, so like if you had 20 walkspeed it’d be 36.
In the localscript it is required to send the FireServer to lower the stamina on the server; (if at 0, it will cease to run lowering the ws by 16, sends a FireClient to disconnect the shift holding so it could regenerate. HOWEVER, you can only let go and go back to running at >30 stamina)

Whenever it is NOT holding, after 1 second, the server regenerates.

See, I’m sensitive about anti exploit. The client has full control over his/her pc and thus can exploit everything locally.

I want to know how RemoteEvents can be detected when sent in an interval of time on the server. For each player, too :grimacing: The check is essential b/c if its not being sent then it assumes its not running so it sets it to what the player’s walkspeed should be, THUS resetting what the exploiter’s walkspeed had set on the client.

PS. I need a better way to store a set walkspeed, ex. Player with 16 ws, has an ability that increases his ws to +8. So 24. What happens if he changes his ability? Too much monitoring adds unnecessary code and memory usage. And I need it to be accessible everywhere.

PSS. People noclip and fly in my place too. I actually can’t find a way to stop this. So even if I patch walkspeed, they always find a way to manipulate unfair movement. Any way to stop this?

Run a check every 0.05 seconds, 20 times (to make it check for a second) to see if the player hasn’t held shift for a whole second, and if shift is pressed, break the loop, and return false. Otherwise, return true to the player releasing shift for 1 second.

But in the client, they could modify and delete that code.

Something practical on the server.

Sorry, my mistake.
I was trying to say that maybe you could fire an event when the player presses/releases shift and check the timing and speed changing from the server, and fire another event telling the client to regenerate stamina if the check-to-see-if-sprint-is-released loop is unbroken, or something similar to that.

Instead of sending repeatedly over a certain interval, just send start/stop events. Your code would look something like:

playerStamina = {Player1=100, Player2=100, Player3=100}
sprintingPlayers = {}

start.OnServerEvent:Connect(function(invoker)
    local start = tick()
    local maxSprintTime = playerStamina[invoker]/staminaConsumedPerSecond

    -- Start sprinting
    sprintingPlayers[invoker] = start
    
    --Stop sprinting if client doesn't stop on their own
    delay(maxSprintTime, function()
        if sprintingPlayers[invoker] == start then --won't continue if stopped or started again
            sprintingPlayers[invoker] = nil --exploiter did not send signal or high latency
        end
    end)
end)

stop.OnServerEvent:Connect(function(invoker)
    if not sprintingPlayers[invoker] then return end --Exploiter firing

    local timeSprinted = tick()-sprintingPlayers[invoker]
    -- Stop sprinting
    sprintingPlayers[invoker] = nil
    -- Consume stamina
    playerStamina[invoker] = playerStamina[invoker] - staminaConsumedPerSecond*timeSprinted

   addToRegenQueue(invoker)
end)
3 Likes

Yeah, I just put the first method I thought of rather than thinking what would be best. Yours is the better way of doing it.

I would just handle all sprinting code on the client anyways since they can change their speed regardless.

1 Like

Well, there could be a check from the server to make sure the player is at the speed they are supposed to be.