Hey, I don’t really understand this can you write a simple explanation?
Magnitude is the distance between two vectors, or in your case. The distance between when the character’s position was checked before and the character’s position after waiting 0.5 seconds.
With this you can measure how fast the player is walking/flying/any way of moving from point A to point B, and you can calculate their walkspeed from there
No it is not laggy. Although there can be improvements, this is far from laggy.
If you have an interval of 5 seconds, the player may die then respawns within that interval, thus the code still runs. It’s better if you just checked the Humanoid.Health
instead
Vector.Magnitude
is a property that measures the scalar distance of the vector.
Examples:
Vector3.new(4,0,0).Magnitude -- 4
Vector3.new(0,3,4).Magnitude -- 5
Vector3.new(7,0,3).Magnitude -- 7.61577
The third example may be weird, but that is actually the distance of 7, 0, 3
Also, here is a better copy of your code.
local XZVector = Vector3.new(1,0,1)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local Humanoid = char:WaitForChild("Humanoid")
local OldPos = HumanoidRootPart.Position
while Humanoid.Health > 0 do
wait(0.5)
local CurrentPos = HumanoidRootPart.Position
local Distance = (CurrentPos - OldPos)*XZVector
if Distance.Magnitude > 9 then
HumanoidRootPart.Position = OldPos
end
OldPos = CurrentPos
end
end)
end)
You may see that I have XZVector
in there. This is used to ignore the vertical distance.
I have a question, is 9 half the walkspeed of the player? I’m talking about these
Ah smart, then the script is not running if your dead. Also factored in the magnitude tysm! How would I add different features to it though?
For your question, I don’t know. In the tutorial it was 10 which made the max walkspeed you had 32 before the AntiCheat kicked in, I changed it to 9 which made the max walkspeed you can have 21.
You mean these things?
Jump power detection depends on your game. If you can fly in-game, then it reduces potential. If there are extreme knockbacks, or stuff that fling you upwards, there may be false positives.
Noclip detection is not really that simple. There are many things to check for noclip.
God mode? What exactly do you mean?
Like everything else, the speedhack detection has its flaws too. If the player gets flung like a hundred studs per second, the speedhack says that the player is moving too fast. This speedhack is more like a speed cap.
God mode as in your health being over 100.
Oh, it is actually impossible to go beyond your maxhealth. Even if the exploiter changed their maxhealth, it only applies for the client.
kinda wrong, they have some funny method to go god mode without even messing these properties, they parent the humanoid to nil and make some mover script for the character. it works
Alright so then with that being said, we just have to check for every change of the Humanoid’s Health.
Humanoid.HealthChanged:Connect(function(newHealth)
if newHealth > 1000 or Humanoid.MaxHealth > 1000 then
print("They are godding...")
Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
end
end)
To prevent anyone from god-modding… This may not be as accurate as it’s still prone to false positives, but this would mainly go over everyone’s expectations.
To counter god-mode it is kind of what @commitblue said e.g
they parent the humanoid to nil
They delete the server-sided Humanoid and create their own local one that they have control over but to counter this you can use the .ChildRemoved
event e.g
Player.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
character.ChildRemoved:Connect(function(v)
if v:IsA('Humanoid') then plr:Kick('god mode') end
end)
end)
end)
Edit: this does work and it has been tested
To counter walkspeed events I recommend using a ‘RunService’ event and comparing their current position with their last e.g (Vector3.new(oldpos) - Vector3.new(currpos)).Magnitude
and then check what if they are moving x studs in a second and if it is abnormal you could give them three false positives and place them back into their original positon but if they continue speeding then kick them
I believe this dosent work if your just using parent nil. Maybe check for parent too
There is no need to check for the parent because ChildRemoved
is checking what child has been taken out of (if an instance in the character has been parented to something else); so if the exploiter deletes their server-sided Humanoid the changes would replicate to the server (Humanoid would be removed and the server would detect this change) and they make their own local one which the server cannot see - so this is a simple solution to countering this specific problem.
You could have a script (assuming that is that script that would handle anti-cheat), to clone all possible parts within your map and size them like a stud smaller keeping it’s position, making them uncollidable and adding a touch event to detect any possible no-clipping. It can be easily created by just doing this:
for partsInWorkSpace, part in ipairs(game.Workspace['Your map goes here']:GetChildren()) do
local antiCheatClone = part:Clone()
antiCheatClone.Size = Vector3.new(antiCheatCode.Size.X - 1.2, antiCheatCode.Size.Y - 1.2, antiCheatCode.Size.Z - 1.2)
antiCheatClone.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
-- do something ig
end
end)
end
again this is just an idea of what you could do, some of it might be scuffed because i haven’t tested on this
A better way to check for noclip is raycasting down from the player and checking if the object is solid (CanCollide on)
I recommend only kicking the player if they are in the middle of the solid object or are making their way through one because sometimes players are able to stick their hands or legs through solid objects:
This is a great tutorial on explaining how to make good anti-cheats for you game I highly recommend checking it out: A Guide to Making Proper Anti-Exploits
Thanks! I’ll check that out. Also thanks for the help everyone!
How could I disable the anticheat when the Player is getting teleported by the server? (ex: Player clicks the play button and is teleported to a random place on the map)
Err. The script here was never intended for marketplace use. I highly advice against using it, at the time I was researching how to make one. Then I figured I should learn LUAU more, If your looking for an AntiCheat I recommend SimpleAnticheat
Its free btw and one of the best ones on the platform. Hope it helps.