Hey there! I have a remote function that basically every two seconds, a local script invokes it and my server-script lets say prints “Passed Verification”
Let’s say I deleted the local script on the players side, the invokes end, like normal
I stopped it after 12 seconds (every two seconds its invoked)
Is there a way that a server-script can detect if the remote function hasn’t been invoked for a set amount of time?
Here’s a concept of what Im trying to achieve:
local Remote = game.ReplicatedStorage.RemoteEvent
if Remote:LastInvokeTime < 5
print("Wow")
else
end
Make a variable and name it lastCalled. Whenever the remote event is fired, set this variable to tick(), which is a function that scripters commonly use to keep track of time, and it returns the number of seconds since 1970 at the time the function is called.
On a fresh new line of code (not inside the server invoke function), create a loop that checks if it has been x seconds since the server has been invoked. You can do this by comparing the current tick() with the time the server was last invoked.
Edit: lol I forgot it should do something when the event is not fired. new strategy just using wait()
local threshold = 2
local tag
local function onFired()
local newTag = {}
tag = newTag
task.wait(threshold)
if tag == newTag then
--sound alarm
end
end)
event.OnServerEvent:Connect(onFired)
onFired() -- to make sure the localscript wasn't disabled from the start
I implanted this with a local script, when the player deleted a local script on their side, after no invokes (with of course a verification code to know if someone is manipulating it), it detected that it was removed, resulting in Connection Bad.
Well actually, this works for one player who logs in and starts the localscript shortly after the script starts, but with multiple players you will have to make it a bit more complicated, using Players.PlayerAdded and such. Also it’s possible to have a latency over 2 seconds sometimes, so it’s not a perfect anti cheat measure, if that is what you intended.
I did make it a Players.PlayerAdded, etc, this was just the last part I needed. the latency isn’t two seconds, since I’m a bit more flexible I’ve put 5, there is a few large security measures in place to make sure of it, I can’t go into detail, but yea.
local threshold = 2
local tags = {}
local function onFired(plr)
local newTag = {}
tags[tostring(plr.UserId)] = newTag
task.wait(threshold)
if tags[tostring(plr.UserId)] == newTag then
--sound alarm
print("Player ", plr.Name, " alarm!")
end
end)
event.OnServerEvent:Connect(onFired)
local playerService = game:GetService("Players")
playerService.PlayerAdded:Connect(function(plr)
task.wait(3) -- give some extra time at the start?
onFired(plr) -- to make sure the localscript wasn't disabled from the start
end)
playerService.PlayerRemoving:Connect(function(plr)
-- remove references to player and disable their alarm
tags[tostring(plr.UserId)] = nil
end)