Would This Anti-Exploit Work?

Hi all! I want to stop exploiting in my future games, so I have decided to come up with an anti-exploit that seems to be working. I wanted some feedback on it and if it would possibly prevent hackers from doing anything to their character. Thanks!

local runService = game:GetService(“RunService”)

game.Players.PlayerAdded:Connect(function(player)	
	repeat wait(0.1) until player.Character
	
	local newPlayerDesc = player.Character:FindFirstChild("Humanoid"):Clone()
	newPlayerDesc.Parent = game.ServerStorage.PlayerDescriptions
	newPlayerDesc.Name = (player.Name.."'s Humanoid")

	runService.Heartbeat:Connect(function(deltaTime)

		if player.Character:FindFirstChild("HumanoidRootPart") then

			local playerPos = player.Character.HumanoidRootPart.Position

			wait(1)

			if (playerPos - player.Character.HumanoidRootPart.Position).magnitude >= 50 then
				player:Kick("No hacking, thanks.")
			end

		end

		if not player.Character:FindFirstChild("Head") or not player.Character:FindFirstChild("HumanoidRootPart") then
			player:Kick("No hacking, thanks.")
		end
		
		if player.Character.Humanoid.HipHeight ~= newPlayerDesc.HipHeight then
			player:Kick()
		end
		
		if player.Character.Humanoid.MaxHealth ~= newPlayerDesc.MaxHealth then
			player:Kick()
		end

		if player.Character.Humanoid.Health ~= newPlayerDesc.Health then
			player:Kick()
		end

	end)

end)

What are you setting the walkspeed to for testing?
RunService.Heartbeat fires almost 60 times a second IIRC, and you’re seeing if they moved >50 studs within one frame

for it to trigger, you would have to set the walkspeed to 60*50 = 3,000

EDIT: Also, when a player dies, its possible for their head to be deleted, so kicking them for not having a head would kick innocent players

1 Like

I am setting the WalkSpeed to their normal speed, and yes, I am seeing if they moved 50 studs within 1 frame in case they teleported or something along those lines.

First of all, using RunService is unnecessary and would take up a lot of resources. You should check these every second in a while loop instead.

Also, I don’t see why you need to clone the Humanoid just to check if any of its properties change. You could just state their default values in the script when checking for any differences.

There’s also no point to checking whether the player doesn’t have a Head or a HumanoidRootPart because they’d just die if they deleted them. But if you do want to persist on doing so, I suggest using AncestryChanged() to detect objects being deleted.

Lastly, not all Humanoid properties properly replicate to the server. If you change the HipHeight on the client and check it on the server, it’d appear normal for the server but different on the client. You should implement another type of check using raycasts to detect any HipHeight changes.

Overall, it’s a decent script that would mostly work but needs some polishing and rethinking. As you develop your anti-exploit knowledge, the script will undoubtedly become better in the future.