Anti-Exploit help

Alright, so I’m planning on using an anti-exploit to (HOPEFULLY) stop some common exploits. However, my question is this: how would I make it so that the script excludes ME, the game owner? So for example, it would kick those who fly but if I do it, I won’t be kicked.

Could anyone help me on how I could add it to the code below?

local Players = game:GetService("Players")
	
local LocalPlayer = Players.LocalPlayer

repeat wait() until LocalPlayer
repeat wait() until LocalPlayer.Character

local Character = LocalPlayer.Character

Character:WaitForChild("HumanoidRootPart").ChildAdded:connect(function(Obj)
	if Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition") then
		LocalPlayer:Kick("Suspected exploiting. Exploiting is not allowed.")
	end
end)
3 Likes

Basically do an if check to exclude yourself above by your name,

if LocalPlayer.Name == "Iluckvy" then
print("Can't ban game owner")
Else
LocalPlayer:Kick(--Reason here)

You can also do this using a userId

if LocalPlayer.UserId== UserIdHere then
print("Can't ban game owner")
Else
LocalPlayer:Kick(--Reason here)
3 Likes

You could add on to this part:

if LocalPlayer.Name ~= "lluckvy" and (Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition")) then

(edit) cakefarmer’s is better since it doesn’t bind an un-needed event listener.

1 Like
local Players = game:GetService("Players")
	
local LocalPlayer = Players.LocalPlayer

repeat wait() until LocalPlayer
repeat wait() until LocalPlayer.Character

local Character = LocalPlayer.Character
if not LocalPlayer.UserId == (143862030) then
Character:WaitForChild("HumanoidRootPart").ChildAdded:connect(function(Obj)
	if Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition") then
		LocalPlayer:Kick("stop hacking noob")--EDIT - You can edit the kick message to anything you want.
	end
end
end)

EDIT: i changed the Checking to UserId incase you change your name and i REVAMPED my script

2 Likes

Also just so you know, this is in a local script from what I can see. This won’t really work on exploiters.

1 Like

I’ll try out each reply.
@SaifLachmann @Blokav @cakefarmer

Also, is there a way to make a list of people as opposed to just me?

Adding onto this your kicking the player from the client which will not kick the player properly.

You could possibly add a table of ID’s to whitelist.

I also rewrote the code to use better practices and explained them in comments.

local whitelisted = { 143862030 } -- your id

local Players = game:GetService("Players")
local client = Players.LocalPlayer

local character = client.Character or client.CharacterAdded:Wait()
-- ^ much faster, more efficient and more reliable than repeat until

character.DescendantAdded:Connect(function(descendant)
    -- it could have been inserted to their torso not just HRP
    if descendant:IsA("BodyMover") and not table.find(whitelisted, client.UserId) then
        -- BodyForce, BodyGyro, etc inherit from BodyMover, so account for all those with 1 call
        client:Kick("blah")
    end
end)

Don’t rely on this though; client-sided anti-kicks are possible. So is disconnecting connections.

2 Likes

Welp, I’m just in desperate need of some type of protection.

From what I can assume you aren’t a scripter. I’d suggest maybe look at some videos about how exploiters can manipulate the client or use anti exploit systems which people have made.

I revamped my script

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local allowed = {143862030,116105780}
repeat wait() until LocalPlayer
repeat wait() until LocalPlayer.Character

if not table.find(allowed, LocalPlayer.UserId) then
	LocalPlayer.Character:WaitForChild("HumanoidRootPart").ChildAdded:connect(function(Obj)
		if Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition") then
			LocalPlayer:Kick("no hacking noob")
		end
	end)	
end

if you want a amount of players that can instead of just you. --[[I put my userid in there because I didnt know who else, you can change that ]]

2 Likes

I think that if it’s a LocalScript (it should be to make it work- exploiters mess around the client, remote events and functions), you aren’t really able to stop them.

Let’s say that I am an exploiter. Your game kicks me out for hacking. I realize that somewhere in the workspace, or my player gui is a script that detects that I am hacking and kicks me when I do so. When I realize that I just simply join your game, use exploit that prints all descendants in workspace, my player gui etc. and disable the LocalScript that prevents me from exploiting.

Let’s get back to the topic. You said that you want the script not to kick you. Your script should look like this:

local Players = game:GetService("Players")
	
local LocalPlayer = Players.LocalPlayer

repeat wait() until LocalPlayer
repeat wait() until LocalPlayer.Character

local Character = LocalPlayer.Character

if player.Name ~= "Iluckvy" then
Character:WaitForChild("HumanoidRootPart").ChildAdded:connect(function(Obj)
	if Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition") then
		LocalPlayer:Kick("Suspected exploiting. Exploiting is not allowed.")
	end
end)
end
2 Likes

I recommend doing a check at the beginning of the script, vs in the event listener or after variables are set. For example,

local Allowed = {"Name1", "Name2"} -- List of allowed users
local LocalPlayer = game.Players.LocalPlayer

if table.find(Allowed, LocalPlayer.Name) ~= nil then -- Is the player's name in the allowed list?
    script:Destroy() -- Destroy the script. (Personally it kinda bothers me if a script just sits there doing nothing lol)
else -- Are they not in the allowed list?
    -- Execute the program normally.

But as others have pointed out this’s a band-aid solution - I recommend looking into ways of detecting them cheating from the server, such as distance checks and etc.

EDIT

Just an idea, but would using an array to hold so many indices of the player’s position work? What I mean is if the script detected some sort of strangeness with the player, it would keep a count of that and how often it’s occurring. Think that might be a viable thing to accomplish?

1 Like

I’m trying to figure out a way to do this on the server rather than the client.

Could I add a line of code that checks if the script is disabled and re-enables it?

EDIT: Nevermind, just realized that wouldn’t work.

I don’t think exploiters even disable or destroy scripts in the first place to stop them. They probably disconnect connections, force them to error by changing constants, globals, or etc… or maybe they have api to straight up stop them without erroring or disabling the script.

2 Likes

well you could do

local runservice = game:GetService("RunService")
local admins = {143862030}
game.Players.PlayerAdded:Connect(function(player)
	runservice.Heartbeat:Connect(function()
		local character = player.Character
		player.Character:WaitForChild("HumanoidRootPart").ChildAdded:connect(function(Obj)
			if not table.find(admins, player.UserId) then
				if Obj:IsA("BodyGyro") or Obj:IsA("BodyVelocity") or Obj:IsA("BodyPosition") then
					player:Kick("Exploit Detected / Not Allowed")
				end
			end
		end)
	end)
end)

something like this on the server

1 Like

This won’t work. Exploiters are running their code on their client and so the instances are created on the client. The server won’t see any new instances added to the character. Also that code is awfully inefficient.

For a server-side anti exploit you can’t detect instances being added or even changes to humanoid properties. You would have to monitor changes in their character’s position to see if they are going too fast, or if they’re somewhere they’re not supposed to be, etc.

I know, but lluckvy wanted an example so.