Basically I’m using PlayerAdded
to get the player upon joining. This is being used for some sort of testing for an anti-cheat. With this, the data is then sent to a Discord Webhook when the player joins, logs data, etc. However, sometimes the player data is sent with incorrect information. This was fixed using a cache system to prevent the user’s data from being obtained all at once.
This is because the remotes are fired every 5 seconds
local remoteFiringCache = {}
Send Cached Data
event.OnServerEvent:connect(function(plr)
remoteFiringCache[plr.Name]=os.time()
sendcount = 0
while true do
wait(1)
if Players:FindFirstChild(plr.Name) then
if os.time() - remoteFiringCache[plr.Name] > 7 then
wait(1)
plr:Kick("Attempting to edit local scripts.")
antilevel = 5
end
end
if antilevel == 5 then
description = plr.Name.." has triggered the anti cheat."
color = 16711680
violation = "Attempting to modify client"
sendWebhook(plr)
break
end
end -- While Loop end
antilevel = 0
lastremotefire = 0
end)
Clear Cached Data
game.Players.PlayerRemoving:Connect(function(plr)
remoteFiringCache[plr.Name]=nil
end)
Purpose of it
This is being used to calculate the time between remotes being sent in a minor attempt to counter the deletion of local scripts. While this can still easily be bypassed by firing remotes manually, I still need to improve.
The Question
How would you go about caching the same sort of data and requests on a player join?
Full Code
local url = "" -- Removed for reasons
local http = game:GetService("HttpService")
local Players = game:GetService("Players")
local repstorage = game:GetService("ReplicatedStorage")
local event = repstorage.BayAnti:WaitForChild("RemoteEvent")
lastremotefire = 0
local remoteFiringCache = {}
antilevel = 0
function sendWebhook(plr)
local modifydata = {
['embeds'] = {{
['title'] = plr.Name,
['description'] = tostring(description),
['color'] = tonumber(color),
['url'] = "https://roblox.com/users/".. plr.UserId .."/profile",
['author'] = {
['name'] = plr.Name,
},
["thumbnail"] = {url = "https://i.imgur.com/fuqp1WY.png"},
['fields'] = {
{
['name'] = "Game Link:",
['value'] = "https://www.roblox.com/games/".. game.PlaceId,
},
{
['name'] = "Violation:",
['value'] = violation,
},
{
['name'] = "User ID:",
['value'] = plr.UserId,
},
{
['name'] = "Logging Information",
['value'] = plr.Name..":"..plr.UserId,
}},
["footer"] = {text = "Bay's Anti-Exploit".." ⋅ ".. "Bay#6969 (209187780079648778)"}
}}
}
local succ,err = pcall(function()
local finaldata = http:JSONEncode(modifydata)
sendcount = sendcount + 1
if sendcount == 1 then
http:PostAsync(url, finaldata)
end
end)
if not succ then
warn(err)
end
end
event.OnServerEvent:connect(function(plr)
remoteFiringCache[plr.Name]=os.time()
sendcount = 0
while true do
wait(1)
if Players:FindFirstChild(plr.Name) then
--print(os.time() - remoteFiringCache[plr.Name])
if os.time() - remoteFiringCache[plr.Name] > 7 then
wait(1)
plr:Kick("Attempting to edit local scripts.")
antilevel = 5
end
end
if antilevel == 5 then
description = plr.Name.." has triggered the anti cheat."
color = 16711680
violation = "Attempting to modify client"
sendWebhook(plr)
break
end
end -- While Loop end
antilevel = 0
lastremotefire = 0
end)
game.Players.PlayerRemoving:Connect(function(plr)
remoteFiringCache[plr.Name]=nil
end)
I will also take any suggestions or recommendations on improvement! Thanks guys!