Anti speed exploits not working

Hello there, I am trying to add a script to stop exploiters from increasing their speed from the default speed (16). I am not a script and I don’t know much about scripting so I do not know why this script isn’t working.

It’s a server script placed into StarterCharacterScripts

Script:

while true do
	wait(1)
	if script.Parent.Humanoid.WalkSpeed >= 22 then
		Player = game.Players:GetPlayerFromCharacter(script.Parent)
		Player:Kick("Speed exploits detected.. You have been kicked for use of exploits.")
	end
end
1 Like
  1. Scripts dont run in StarterCharacterScripts
  2. WalkSpeed doesn’t replicate, use magnitude
  3. Its better to do while task.wait(1) do instead of while true do
3 Likes

It wouldn’t work because client changes wouldn’t be replicated to the server, the server wouldn’t see the value being changed from the client. You gotta do it on the client side, also just listen for property change so you don’t have to run a loop.

Would I be able to place the script in ServerScriptService for it to work?

Read:

You clearly are at an extremely early stage of scripting, I recommend trying to understand the roblox documentation and its formats

theres nothing wrong with while true do

and when u say magnitude you mean measure the x and z position of the character making sure the magnitude doesnt consistently change to sharply

Its just cleaner to do above compared to below

while task.wait(1) do
    
end

while true do
    task.wait(1)
end

ya

You should try a simple thing but hide it well, some exploiters could delete it.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Char)
  while wait() do
         if Char.Humanoid.WalkSpeed >= 22 then
              plr:Kick("Speed Exploits Detected.. You were kicked you big meanie hacker")
            end
     end
  end)
end)

cleaner maybe but its not as clean as just

while wait(1) do 

end 

but thats besides the point it is actually bad practice because the value of wait() isnt a true value its a “truey” value and it takes longer for the computer to decide wait is true than true is true

1 Like

yes but then ur using the deprecated wait global (not sure if it is yet, but tis soon to be)

wasn’t actually aware of this, thx for the heads up :+1:

Server Scripts don’t work in StarterCharacterScripts. They only work in ServerScriptService and Workspace (Script | Roblox Creator Documentation).

This is more efficient:

game.Players.PlayerAdded:Connect(function(plr)
	local hum = workspace:WaitForChild(plr.Name).Humanoid
	hum.Changed:Connect(function()
		if hum.WalkSpeed > 16 then
			plr:Kick()
		end
	end)
end)

Thats because script.Parent is not the player’s character. Use game.Players.PlayerAdded to get the player’s character

[ I have tested this and yup, it works! ]

[ Backup might not work, but auto enabler will! ]

  1. Put LocalScript into StarterCharacterScripts

LocalScript Source >

spawn(function()
	task.wait(.5)
 
	local Backup = script:clone()
	local Character = script.Parent
	local RunService = game:GetService("RunService")

	local Player = game.Players:GetPlayerFromCharacter(Character)
	local ActualCharacter = Player.Character or Player.CharacterAdded:Wait()
	local ActualHumanoid = ActualCharacter:WaitForChild("Humanoid")


		ActualHumanoid.Changed:Connect(function(Property)
			if Property == "WalkSpeed" then
			game.ReplicatedStorage:WaitForChild("Actions"):FireServer("Speed", ActualHumanoid.WalkSpeed)
			end
		end)

	
	RunService.RenderStepped:Connect(function()
		if script == nil then
			Backup.Parent = ActualCharacter
			
		end
		if script.Disabled then
			script.Disabled = false
		end
	end)
	
	
	-- // Write your whole code here... 
	
end)

  1. Put Remote Event into ReplicatedStorage and name it: Actions

  2. Put Script [Server script ofc] Into ServerScriptService

Script’s Source >

spawn(function()
	task.wait(.5)
	
game.ReplicatedStorage.Actions.OnServerEvent:Connect(function(Player, Action, Value)
	if Action == "Speed" then
		local Character = Player.Character or Player.CharacterAdded:Wait()
		
		local Humanoid = Character:WaitForChild("Humanoid")
		
		if Value >= 22 then
			Player:Kick("Speed exploits detected.. You have been kicked for use of exploits.")
		end
	end
	end)
	
	-- // Write your whole code here... 
	
	
	end)

  1. Enjoy developing your game and goodluck to you!

[I believe this will help a lot.]

// Goodluck developers.

I recommend to look at this when making anti-exploits > Remote Functions and Remote Events