Anticheat not working exactly as supposed to

I am trying to make a anticheat script to detect speed & jumppower ( I have never made an anticheat before) (possibly flying and teleporting too, but I’ll have to experiment with that), but when I run my game, the jumppower spazzed out and the player keeps dying.

Example:
https://gyazo.com/e4f7a0414ca4fffb4c59f5f81e0799b2

game.Players.PlayerAdded:Connect(function(player)
	game:GetService("RunService").Heartbeat:Connect(function()
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:FindFirstChild("Humanoid")
		
	if character and character.PrimaryPart and humanoid then
			character.PrimaryPart.Velocity = character.PrimaryPart.Velocity.Unit * character.PrimaryPart.Velocity.Magnitude
			if (character.PrimaryPart.Velocity.Magnitude) > humanoid.WalkSpeed then
				print("z")
			end
		end
		end)
end)
1 Like

You are trying to detect speed and jump power, so why are you changing the Velocity?

1 Like

Because you can’t just do

if humanoid.JumpPower or humanoid.WalkSpeed > 10 then

Unless I misunderstood what you said.

1 Like

Probably you just want to change velocity when the statement is true? Try this instead.

game.Players.PlayerAdded:Connect(function(player)
	game:GetService("RunService").Heartbeat:Connect(function()
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:FindFirstChild("Humanoid")
		
	    if character and character.PrimaryPart and humanoid then
			if (character.PrimaryPart.Velocity.Magnitude) > humanoid.WalkSpeed then
				character.PrimaryPart.Velocity = character.PrimaryPart.Velocity.Unit * character.PrimaryPart.Velocity.Magnitude
			end
		end
	end)
end)
1 Like

You are assigning the velocity to a new velocity every time you check if the player’s character exists and has a humanoid, thus constantly changing the velocity and causing you to have that “spazzing out”.

What do you suggest I do?
(Sorry for being such a noob at this sort of thing)

WalkSpeed does not replicate to the server though?

Sure, I don’t know why you used it in your script but character magnitude does.

Sorry, what?

tryingtomake30characters

I said yes that is true that walk speed does not replicate to the server. I just saw that you are trying to get a walk speed from server in the if statement. I think that you can calculate the walk speed from character magnitude on specific amount of seconds passed (from previous magnitude and decreasing it by a new one after amount of seconds). I’d highly recommend checking up already made anti-exploits for this kind of a problem.

Oh alright, sorry for the misunderstanding. I’ll go look at some others I guess. Thanks for the help.