Help with an anti-cheat script

So, i’m trying to make an Anti-cheat system, i have a Run system that runs entirely on the client side, so that means that its easily modifiable for exploiters, so what should i do?

i was thinking about save the player position in a variable, and then after some time see the player position again and compare these two values, or should i try use LinearVelocity? if no, what should i do?

Anyway, this is my code:

-- Function to handle stamina depletion while running
local function handleRunning()
	while run and Stamina > 0 and run == true do
		if Hum.MoveDirection.Magnitude > 0.1 then
			Stamina = math.max(Stamina - 1, 0)  -- Decrease stamina, ensuring it doesn't go below 0
			print("Foi")
			Label.Text = Stamina
			Hum.WalkSpeed = 24
			Remove_Event:FireServer()
			task.wait(DepleteRate)
		else
			Stamina = math.min(Stamina + 1, 100) --If you are holding shift but you are not moving you can regen stamina, you can remove this if you want
			Label.Text = Stamina
			task.wait(RegenRate)
		end
	end

-- Function to handle stamina regeneration
local function handleRegeneration()
	while not run and Stamina < 100 do
		Stamina = math.min(Stamina + 1, 100)  -- Increase stamina, ensuring it doesn't exceed 100
		Label.Text = Stamina
		task.wait(RegenRate)
	end
end

-- Detect when the player starts running
UIS.InputBegan:Connect(function(io, gpe)
	if io.KeyCode == Enum.KeyCode.LeftShift and not gpe and Stamina > 0 and run == false then
		run = true
		handleRunning()
	end
end)

-- Detect when the player stops running
UIS.InputEnded:Connect(function(io, gpe)
	if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
		run = false
		Hum.WalkSpeed = 16
		handleRegeneration()
	end
end)

this is what i wanted to say, if you know how to answer my question, i’m going to be happy to know. :happy4:

Thanks for reading!

1 Like

Make it Server-side

just make server-side functions

protect remote-events

and make function when client presses (RUN BUTTON) they send remote event to server

and then server takes whole job

5 Likes

Going off of what @Microlosofto said you need to make it server sided. Don’t waste your time making client side anti cheat. They can always be bypassed. The most you can do is make it less powerful for exploiters. Exploiters will always have an advantage over other players… it’s just that by making it server sided you can shrink this advantage to being much smaller compared to a client sided anti cheat where they will have an extremely unfair advantage.

4 Likes

thanks for answering, but in the server script, to see if the player changed the WalkSpeed in the local script, should i use LinearVelocity?

3 Likes

I deleted a message because you confused me by saying to check the walkspeed in the local script. You cannot directly stop anything the player is doing using exploits. The best thing you can do is test both position checking and velocity checking and find which one works the best for you. This forum isn’t meant to spoon feed you but rather serves as a means of helping fill in the blanks so you can put the rest together.

2 Likes

cant i do something like this? if the exploiter change the WalkSpeed i can check in the Server Script if the WalkSpeed is not normal?

2 Likes

Nope. You cannot. You must use position checking or velocity checking. The property is different on the client and the server.

5 Likes

Client and Server ownership and Server rejects what client replicates

3 Likes

Also don’t take my word for it. Obviously use an alt account for this. If you go on Jailbreak and run a fly script for example… the game will knock you back if you fly too quickly. If you go nice and slow with it, you can fly. But there’s a limit. That’s what you can do. Jailbreak would never do it that way if Roblox let people check the walkspeed property. That’s the whole point. That’s what we’re stuck with.

2 Likes

Thank you guys, that answers my question.

2 Likes

you’re welcome! Understanding everything is crucial to being a developer. There are certain rules in Roblox that should be changed and improved upon but Roblox doesn’t care enough to do that for us. I believe in doing whatever it takes within reason and ethics to understand things so that you can use that knowledge for good things.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.