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.
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)
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)
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”.
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.