So this is my attempt on making a anti speed exploit (NOTE: THIS IS MY FIRST TIME DOING THIS). This is in a server script and in StarterPlayerScripts. It's not working when I go over 50 or directly on 50. Any help?
local Players = game:GetService("Players") game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local humanoid = char:WaitForChild("Humanoid") while true do wait() if char.WalkSpeed >= 50 then player:Kick("Exploiting") wait(10) end end end) end)
Exploiters change their walk speed client side, which means if you look at the exploiter's walk speed server side it would be unchanged. Another way to check for their walk speed server side is by checking their velocity.
local maxspeed = 22 --The maximum distance the player can travel within a check time. Try to keep this higher than 16. local checktime = 1 --How many seconds we wait before we record their speed. --If we make checktime too fast, like ".1", the script will be recording positions too fast and thus will fail to work correctly! local root = script.Parent:WaitForChild("HumanoidRootPart") --Get HumanoidRootPart so we can keep track of the player's position. local lastcf = root.CFrame --We will store the player's CFrame so that we can move the player there if they seem to be hacking. while wait(checktime) do if math.floor((Vector3.new(lastcf.p.X, 0, lastcf.p.Z) - Vector3.new(root.Position.X, 0, root.Position.Z)).magnitude) > maxspeed then --We compare the length of the last known position, lastcf.p, with the current position, root.Position. If it's greater than maxspeed, they're hacking. --See how we ignored the Y axis in the calculation? Also notice how we rounded on the line above? This prevents an inaccurate reading. print("Hack detected for "..script.Parent.Name.."!") root.Parent:SetPrimaryPartCFrame(lastcf) --The player is hacking! Because this could be a false positive, we DO NOT KICK THE PLAYER. Instead, we peacefully move them back to their last known valid position! end lastcf = root.CFrame --We store the player's position so we can see if they're hacking later! end
Script is from https://devforum.roblox.com/t/how-to-prevent-speed-hacking/210733
It's not a good idea to kick someone as it could be false flagged via other scripts, instead make an accumulative point system that would help (optional, still what I prefer to do)
The reason yours doesn't work is because it's a server script, and changing speed is client sided manipulation. Consider changing it to a local script, which will be less secure, but if you hide it well enough and add enough counter measures to ensure it doesn't get deleted, it will withstand most exploit attacks. Also consider obfuscating so scripts like Infinite Yield Admin won't pick it up with their anti client kick feature
Good obfuscator: https://obfuscator.aztupscripts.xyz/