Tips/Improvements for a basic limb check anti-cheat

--- server script
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
local sss = game:GetService("ServerScriptService")
local kpl = rs:FindFirstChild("randomremote")
local check = rs:WaitForChild("sizecheckclient")
local checkall = rs:WaitForChild("sizecheckall")

local module = require(sss.functions)

local running = {}

local function scheck(character)
	local plr = players:GetPlayerFromCharacter(character)

	if not plr then return end

	if running[plr] then return end

	running[plr] = true

	while plr do
		task.wait(3)

		local plsizetable = checkall:InvokeClient(plr)

		for _,foundplayer in pairs(players:GetChildren()) do
			for name,size in pairs(plsizetable[foundplayer.Name]) do
				local cheating = module.scfa(plr,foundplayer,name,size)
				
				if cheating then
					plr:Kick("cheating")
					running[plr] = nil
					break
				end
			end
		end
	end

	running[plr] = false
end

a = game.Players.PlayerAdded:Connect(function(plr)
	if plr.Character then
		task.spawn(scheck, plr.Character)
	end

	plr.CharacterAdded:Connect(function(character)
		task.spawn(scheck, character)
	end)
end)
--- module script
local module = {}

local limbs = {
	["Head"] = Vector3.new(2,1,1),
	["Torso"] = Vector3.new(2,2,1),
	["Right Leg"] = Vector3.new(1,2,1),
	["Left Leg"] = Vector3.new(1,2,1),
	["Right Arm"] = Vector3.new(1,2,1),
	["Left Arm"] = Vector3.new(1,2,1),
	["HumanoidRootPart"] = Vector3.new(2,2,1)
}

local plrs = game:GetService("Players")
local runservice = game:GetService("RunService")

function module.sc(limbname,cheatingsize)
	for name,expectedsize in pairs(limbs) do
		
		if limbname == name then
			if (cheatingsize - expectedsize).Magnitude > 0.1 then
				print("cheat:", limbname, cheatingsize)
				return true
			end
		end
	end
	
	print("no cheat")
	return false
end

function module.scfa(cheatingplayer,anyplayer,limbname,cheatingsize)
	
	for name,expectedsize in pairs(limbs) do
		
		if limbname == name then
			if (cheatingsize - expectedsize).Magnitude > 0.1 then
				print("cheater: ".. cheatingplayer.Name.. " sees " .. anyplayer.Name.."'s limb: ".. limbname.." as size:", cheatingsize)
				return true
			end
		end
	end
	
	print("no cheat")
	return false
end

return module

--- local script
local players = game:GetService("Players")
local player = players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local bs = rs:WaitForChild("sizecheckclient")
local bsa = rs:WaitForChild("sizecheckall")

bs.OnClientInvoke = function()
	local char = player.Character
	if not char then return {} end
	
	local sizes = {}
	for _,v in pairs(player.Character:GetChildren()) do
		if v:IsA("BasePart") then
			sizes[v.Name] = v.Size
		end
	end
	
	return sizes
end

bsa.OnClientInvoke = function()
	local chart = {}
	
	for _,v in pairs(players:GetPlayers()) do
		if v.Character then
			chart[v.Name] = {}
			
			for _,v2 in pairs(v.Character:GetChildren()) do
				if v2:IsA("BasePart") then
					chart[v.Name][v2.Name] = v2.Size
				end
			end
		end
	end
	
	return chart,player
end

this is a basic size check anti-cheat that ive made for my game, the local script gives size values to the server and server uses module functions to check for the size differences and depending on that kicks the player.

however i do believe we can improve this code or atleast get some tips on how to improve it, because i am only at mediocre level of scripting i believe there is people that can help me improve.

the part that i want to improve is making it more reliable by conducting server checks rather than rely on client to get the data.

edit: server script and module is in serverscriptservice while local script is in playerscripts

Okay so I don’t know what the purpose of this is, but this is super easily bypassable by any hacker with basic knowledge about Roblox don’t even need to hook any functions. That’s because you’re using a remote function which can only have one .Invoke set at one time, so all a hacker needs to do to bypass this is to make a function that just returns that everything is alright Upon Invoke.

Yes i know as i have made a debugging script myself that can bypass this easily, however i am simply asking is there a way to successfully get data from the client without them easily intercepting it? Because the only way to communicate between server and client is by remotes (as far as i know)

The best we game developers can do is security by obscurity. There is unfortunately no way for us to protect local scripts from being tampered with.

You can make it non-obvious that you’re sending over this information somehow.
Either by using an actual obfuscator to hide the script (Though, that makes it obvious you’re hiding something, because obfuscators are ugly)
or disguise it as another datatype instead (instead of sending over a straight Vector3, you can try using a buffer instead, or mangle it into a CFrame, alternatively you could even send over a Color3 too as a sort of Vector3 if you divide the part size by 2048. Lots of options)

Remember that exploiters have the ability to run a “RemoteSpy” which will immediately spot your “sizecheck” RemoteFunction, because you conveniently named it. Hide it within some noise, name it something else, combine it with another system even, so it’s not obvious what RemoteEvent/RemoteFunction is sending that data.

“To confuse the enemy, you must first confuse yourself” (sun tzu, probably)

Hello. This post is already solved, but I just wanted to give a few pointers.

From a scripting standpoint:

  • It’s general practice to have a function’s name tell what it does. E.g. module.scfa isn’t obvious at all and forces us to read the whole function to understand what it does.
  • You do not need to use WaitForChild/FindFirstChild for static objects in a Script (see this video and you can ask AI about this)
  • You do not need to make a new while loop every time the character spawns - This is a massive memory leak!! Instead, just put the while loop outside any scope and loop through every player. That way, you only have one while loop for the entire system and don’t need to worry about lifecycle/cleanup.
  • Isn’t magnitude for distance checking? Why are you doing (size - size).Magnitude > 0.1? Instead, just check if its not the same, limb sizes don’t change anyway: if cheatingsize ~= expectedsize then.
  • Your server OnServerInvoke is not protected! Use nil and type checks here otherwise the script will error and stop running, allowing the exploiter to freely manipulate their limbs:
local plsizetable = checkall:InvokeClient(plr)
if typeof(plsizetable) ~= "table" then warn("remote tampering", player) return end -- includes nil
-- also validate everything in the table:
for name: string?, size: Vector3? in plsizetable do
    if typeof(name) ~= "string" or typeof(size) ~= "Vector3" then
        plsizetable[name] = nil -- remove index from table
        warn("remote tampering", player)
    end
end

Remember, the client can simply disable your LocalScript. Even if you add some system that checks if the player hasn’t sent an event for x time, they can still falsely send values to trick the server everything is alright.

While it’s good experience to make client anticheats, most people (including me) will discourage it. At the end of the day, basically everything you do on the client can be worked around, even if your code is hidden. I’d say it’s not worth making client anti-cheats, at least if your game isn’t PvP.

The best thing to do is validate parameters in server events handlers (OnServerEvent, OnServerInvoke) and designing your game in a way where the server controls everything. And with server authority coming around, it’s likely you wouldn’t even have to worry about making server-sided anti-fly/teleport scripts.

Okay so I know that this is already solved but for a base generally keep a handshake remote that sends every like set amount time for example every 2 seconds and if the handshake gets blocked then you can moderate as possible. Yet don’t keep the same handshake use stuff like NONCEs (Numbers only used Once) while encrypting the traffic if the NONCE is incorrect then moderate aswell.

It’s been a while since I’ve been in the anti-cheat side but here’s what I’d do to make it to stop tampering:

  • Put a local script to handle anti cheat in replicated storage
  • Use as little functions in the anti cheat to stop them from being hooked, and don’t require modules inside the local script (easier to tamper with)
  • Add something like this at the top of your script:
script:Destroy()
script = nil

This will attempt to remove the script from the nil instances and harder to find I’m not sure if this is still valid but it should be good

  • Obsfucate the script itself (so even when it’s found it’s harder to work with)
  • Add a handshake with data of your anticheat that’s encrypted by the client and have a nonce that’s generated at each NONCE, making sure the NONCE can be verified at the server and the handshake be decrypted