AntiCheat Script (Local)

Hey, so I’ve been working on an AntiCheat script that detects if a player has activated the AntiCheat and sends a Discord message to a server telling me that an exploiter has tried to cheat inside of my game. Now, I do need some help revising some stuff a little bit. If anyone could help with revising some piece of the code, I’d highly appreciate it! I would also like any suggestions to be added into this AntiCheat script, but that’s optional.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local StarterGui = game:GetService("StarterGui")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheatEvent = ReplicatedStorage.CheatEvent

while wait(1) do
	-- Basic Exploits
	if Humanoid.WalkSpeed >= 17 then
		local reason = "WalkSpeed exceeds 16"
		CheatEvent:FireServer(reason)
		task.wait(1)
		Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
	end 
	if Humanoid.JumpPower >= 51 then
		local reason = "Jump Power exceeds 50"
		CheatEvent:FireServer(reason)
		task.wait(1)
		Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
	end
	if Humanoid.MaxHealth > 100 then
		local reason = "Extra Health"
		CheatEvent:FireServer(reason)
		task.wait(1)
		Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
	end
	
	-- AntiFly
	if Character == false then continue end
	if Humanoid == false then continue end
	local HumanoidState = Humanoid:GetState()
	if HumanoidState == Enum.HumanoidStateType.PlatformStanding then
		local reason = "Flying"
		CheatEvent:FireServer(reason)
		task.wait(1)
		Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
	end
end

i’m pretty sure exploiters can remove local scripts or thats how it has been before byfron, don’t do it in a local script

Is it because of inserting a Dex GUI? If so, I could make another script that detects anything getting imported into the Player’s GUI.

i’m pretty sure it gets inserted in the core gui and they can just delete the local script when they write a code, its not a good idea to make a anti cheat on the client

True, true. I’ll see what I can do about it.

Would it make more sense to just measure the player’s speed by simply subtracting the current position from the previously saved position on the server and see if the player is moving faster than they should? Not sure what to do about ping issues.

i mean pretty sure you can do a calculation and include the players ping so it wont be so horrible and get flagged 3 thousand times by the anti cheat

2 Likes

It’s just that I am not very experienced with exploit protection. But it’s a good idea to never trust the client as you never know what they will do.

Hands down best anti-cheat I’ve ever seen, doesn’t need any more updates, you should keep using this as it is right now, trust me.

That’s the biggest lie right here :sob:

Sometimes LocalScripts are good at handling AntiCheat stuff, but I do have to agree with you.

You are joking right? Like this is almost relying on the possibility that the cheater doesn’t know about the localscript and doesn’t just simply disable it.

well yeah cuz they can directly read the players walkspeed if it gets changed but theres other things to consider like flying and swim flying (exploits) and they can easily delete the local script so its not a good idea

Okay, I transformed the LocalScript into a Script. Nothing seems wrong yet, but I will test it shortly.

local Players = game:GetService("Players")

local StarterGui = game:GetService("StarterGui")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CheatEvent = ReplicatedStorage.CheatEvent

Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	
	while wait(1) do
		-- Basic Exploits
		if Humanoid.WalkSpeed >= 17 then
			local reason = "WalkSpeed exceeds 16"
			CheatEvent:FireServer(reason)
			task.wait(1)
			Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
		end 
		if Humanoid.JumpPower >= 51 then
			local reason = "Jump Power exceeds 50"
			CheatEvent:FireServer(reason)
			task.wait(1)
			Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
		end
		if Humanoid.MaxHealth > 100 then
			local reason = "Extra Health"
			CheatEvent:FireServer(reason)
			task.wait(1)
			Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
		end

		-- AntiFly
		if Character == false then continue end
		if Humanoid == false then continue end
		local HumanoidState = Humanoid:GetState()
		if HumanoidState == Enum.HumanoidStateType.PlatformStanding then
			local reason = "Flying"
			CheatEvent:FireServer(reason)
			task.wait(1)
			Player:Kick("\nYou've been kicked from this server.\nReason: Potential Cheats\nIf there is a mistake, contact me on Roblox.")
		end
	end
end)

UPDATE: WalkSpeed detection does work, so everything in here should be fine. Before anything, I’ve already tested everything inside of the LocalScript so I know if anything works or not before this.

What happens when the player just does teleport hacking and keeps the walkspeed the same? Also doesn’t the walkspeed only update locally when you do these types of hacks?

umm that doesnt work… because they change the walkspeed on client and the server shouldnt be able to detect the walkspeed

1 Like

Exactly! thats what happens a server wont detect it if it changes on client

1 Like

I’ll see what I can do for just teleporting.

1 Like

Well I tested it, and your right. Do you have any ideas on how to fix it?

it isnt a matter of fix, u need to write ur own anti cheat, just checking for walkspeed wont do the trick, u gotta save the players position and when they change their position look for the distance and calculate the actual distance it wouldve taken if their walkspeed is 16 if the distance is more than the one u calculated then they might be exploiting or have high ping so u gotta also calculate the ping somehow