So I made this anti cheat system and I need know if this is the correct way
what does it do:
- it records the player position every 0.5 seconds
- if the player is too far from the old position it gives the player a warning
- you can change the velocity attribute in the player to change the max distance for it to warn
- if the player has 5 warnings the player gets kicked
local function Check(player, character)
if not player or not character then return end
local Magnitude = (character.PrimaryPart.Position - player:GetAttribute("Position")).Magnitude
Magnitude *= 2
if Magnitude > player:GetAttribute("Velocity")+5 then
player:SetAttribute("Warnings", player:GetAttribute("Warnings")+1)
character:MoveTo(player:GetAttribute("Position"))
else
player:SetAttribute("Position", character.PrimaryPart.Position)
end
if player:GetAttribute("Warnings") >= 5 then
player:Kick("Suspicious movement detected please rejoin.")
end
end
game.Players.PlayerAdded:Connect(function(player)
player:SetAttribute("Warnings", 0)
player:SetAttribute("Position", Vector3.zero)
player:SetAttribute("Velocity", 16)
player.CharacterAdded:Connect(function(character)
player:SetAttribute("Position", character.PrimaryPart.Position)
while task.wait(0.5) do
if not player then break end
Check(player, character)
end
end)
end)