How to protect your server from **MOST** cheaters easily 101

I often see servers being demolished by the most blatant “cheaters” where it could be prevented in a super easy way (explosions, peds, teleporting etc.). In this post we detail the easiest way to block or catch cheaters on your FiveM server.

Lets start by the simplest things you can do (i.e SERVER COMMANDS / CONVARS)

Disabling networking sound PlaySoundFrom*

What a headache was when cheaters were playing all those super loud siren sounds (or other) on my server and you couldn’t do anything about it :frowning: Now you can disable it completely by setting this server command

sv_enableNetworkedSounds false

This will also disable legitimate uses of PLAY_SOUND, but your server probably doesn’t use them. Most scripts use an external resource that handles sounds through NUI.

:warning: Setting a required pure client

⚠️ This is something I won't really recommend for most of the server as it is forces a full pure client (depending on the setting)
For example, recently there’s been a lot of RPFs that would crash every person on your server (by manipulating the type of lets say “ambulance” and making it a helicopter, which would lead in a crash for other players

# At this moment there are only 2 levels you can set
sv_pureLevel 1 # Will block all modified client files except audio files and known graphics mods.
sv_pureLevel 2 # Will block all modified client files.

Block all control requests (entity authority?)

Ever wondered why cheaters are able to make all cars fly? Or delete other player’s cars? (really annoying isn’t it?)

A super easy solution for all this would be setting sv_filterRequestControl

# There's 4 modes of this setting
# -1: Default, equivalent to 2 at this time, but will also warn in console.
# 0: Off. Also disables the routing bucket/entity lockdown-based policy.
# 1: Blocks control requests to entities controlled by players (currently, occupied vehicles only) that have existed for more than sv_filterRequestControlSettleTimer milliseconds (default 30000) - hereafter referred to as 'settled'.
# 2: Blocks control requests to all entities controlled by players.
# 3: Blocks control requests to all entities controlled by players, and any 'settled' non-player entities.
# 4: Does not route REQUEST_CONTROL_EVENT whatsoever.

# I would **personally** recommend setting it to 4
sv_filterRequestControl 4

Basically, this would block all control request over given entity by unauthorized client

:warning: Entity lockdown

⚠️ This setting can break many of your scripts that depends on creating entities by the client
A super simple way of blocking user created entities such as custom objects, vehicles, peds etc..

sv_entityLockdown inactive # Clients can create any entity they want.
sv_entityLockdown relaxed # Only script-owned entities created by clients are blocked.
sv_entityLockdown strict # No entities can be created by clients at all.

For more flexibility you could use this native https://docs.fivem.net/natives/?_0xA0F2201F or even handle the events for creating/removing entities!

:warning: Disable networked entity state change

It’s a more specific thing that blocks stuff like exclusive drivers etc.

sv_enableNetworkedScriptEntityStates false

Read more in-depth explanation about commands here!

:warning: Sanitization ConVars

FiveM has a few game_ ConVars that add extra checks to game mechanics that can be abused by cheaters. Add these to your server.cfg

setr game_sanitizeRagdollEvents true -- prevents force ragdoll cheats
setr game_sanitizePlayerAttachment 2 -- prevents vehicles and objects from being attached to players

You can optionally also add this one, which prevents cheaters from messing with other player’s cars, but beware that it completely disables the option to hijack a vehicle with a driver inside by pressing F on a door

setr game_enableVehicleHijackFix true -- prevents vehicle hijack cheats **but also prevents pressing F on the driver door to steal a car**

:warning: Blocking network game events commonly used by cheats

Some base GTA V Network Game Events weren’t made by Rockstar with security in mind and can be easily used by cheaters to obtain weapons or armor. Using the block_net_game_event in your server.cfg, you can prevent these events from working

-- These block common game events cheaters use to get or remove weapons
block_net_game_event "GIVE_PICKUP_REWARDS_EVENT"
block_net_game_event "NETWORK_GIVE_PICKUP_REWARDS_EVENT"
block_net_game_event "REMOVE_ALL_WEAPONS_EVENT"
block_net_game_event "NETWORK_PICKUP_CARRIABLE_EVENT"
block_net_game_event "REQUEST_MAP_PICKUP_EVENT"
block_net_game_event "REQUEST_PICKUP_EVENT"
block_net_game_event "REMOVE_WEAPON_EVENT"

Simple script checks

There are plenty of simple script-level checks that you can use to detect the most common and obnoxious cheaters. Many anti-cheat resources, even free ones, implement these, but we recommend you create your own resources, tailored to your server’s needs.

Keep in mind that these are not fool-proof and as cheats evolve, they can get around such primitive checks. Here are a few easy ones to implement with basic knowledge of scripting:

Client-side

  • Detect if a player is in freecam by checking the distance between GetEntityCoords and GetFinalRenderedCamCoord.

  • Detect No Clip by checking if a ped is high above the ground (GetEntityHeightAboveGround) without being in a vehicle (IsPedInAnyVehicle), parachuting (IsPedInParachuteFreeFall) or falling (IsPedFalling)

  • Detect God Mode cheats using GetPlayerInvincible and GetPlayerInvincible_2

  • Detect infinite stamina cheats by checking if GetPlayerSprintStaminaRemaining is decreasing while the player is running (GetEntitySpeed over 6 and on foot)

  • Detect invisible players by checking these natives IsEntityVisible, IsEntityVisibleToScript, GetEntityAlpha

  • Detect increased weapon damage by checking GetWeaponDamage against known values for each weapon

Server-side

  • Monitor the entityCreating event. If a player is spawning too many peds, they are probably cheating. You can also check GetEntityPopulationType for the created ped - legitimate population peds spawned by a player will have the types 1, 2, 3, 4 or 5. Types 0 and 5 are spawned by a script and if you don’t have a script to spawn them - they are most likely created by the cheater.
    TIP: You can CancelEvent() to prevent the ped from spawning.

  • Monitor the explosionEvent event. If you don’t have explosions disabled and a player is creating too many explosions, they are likely cheating. Do not attempt to cancel explosionEvent, it results in desync.

  • Monitor the ptFxEvent event. If a player is creating too many particles, they are likely using some kind of cheat. Some freecam cheats also use txAdmin’s built-in freecam code, which creates particles with the assetHash `ent_dst_elec_fire_sp`. You can also cancel this event to prevent the particles.

  • Monitor giveWeaponEvent, removeWeaponEvent, removeAllWeaponsEvent. These can all be used by cheaters to modify other player’s weapon. The source of the event is the cheater!

  • If you are in full control of all scripts on your server you can also add more advanced checks, but making sure to exclude all legitimate ways to trigger them. For example, if a ped’s health rises without anyone having used a healing item on them, they might be cheating. Or if a player has suddenly teleported half way across the map without using a teleporter/command, they are also likely cheating.

Read more about server events here!

How do I write secure scripts?

When writing scripts, the base philosophy is to absolutely NEVER trust the client whatsoever.

An example of this would be, lets say you’re roleplaying and you work a job where you collect packages and it gives us money

:cross_mark: WRONG/BAD PRACTICE

-- Some client-side pseucodocode
if IsControlJustPressed(0, 38) then
	if hasEnoughItem("package", 1) then
		TriggerServerEvent("packages:removeItem", "package", 1)
		TriggerServerEvent("packages:addMoney", 5000)
	else
		showNotification("You don't have enough packages to sell")
	end

end

-- Server-side
RegisterNetEvent("packages:removeItem", function(item, count)
	removePlayerItem(source, item, count)
end)

RegisterNetEvent("packages:addMoney", function(money)
	addPlayerItem(source, "money", money)
end)
-- etc...

At the first sight, everything works but when a malicious user comes and see this, they would immediately use it (packages:addMoney) as way to generate infinite money

:white_check_mark: CORRECT/BETTER WAY

-- Some client-side pseucodocode
if IsControlJustPressed(0, 38) then
    if hasEnoughItem("package", 1) then
       TriggerServerEvent("packages:givePackage")
    else 
       showNotification("You don't have enough packages to sell")
    end
end

-- Server side
local sellPosition = vector3(100.0, 0.0, 0.0) -- Some random position doesn't matter here
RegisterNetEvent("packages:givePackage", function()
    local ped = GetPlayerPed(source)
    local position = GetEntityCoords(ped) -- hey fivem gave us this super thingy so we can use it server-sidely what and check people's positions how cool is it!?
    -- Lets double-check if the player is near the sell/give point whatever we called it earlier doesn't matter
    if #(position - sellPosition) >= 10 then -- 10 should be an enough radius to see if the player is close enough for them to sell
        return sendNotification(source, "You are too far away to give packages..")
    end

    if hasEnoughItem(source, "package", 1) then
        removePlayerItem(source, "package", 1)
        addPlayerItem(source, "money", 5000)
    end
   --- you know where it's going more and more checks!
end)

In short, write better code.

Obfuscate your files for production

Thanks to the partnership between Tebex and CFX.re, we can now ship obfuscated scripts for our users.

But how do we server-owners profit from it?

We can obfuscate our files using the FXAP tool created by FiveM so hackers can’t easily dump our client-scripts and look at them (this includes all assets & scripts)

I hope this tutorial helped you have a better understanding about hackers in 2026 2023 and how we can prevent it :smirk_cat:

If not, Im sorry :sob: .

84 Likes

Somebody who cares about secure code wow :clap:

7 Likes

never knew that entityLockdown and sv_enableNetworkedSounds existed :exploding_head: thanks bro

2 Likes

Great post :kissing_closed_eyes:

2 Likes

this has been a big help. thanks!

2 Likes

Thank you for trying to help make the community better!!

2 Likes

Thank you, for your time doing this :rocket:

1 Like

Great post, thanks dude!

1 Like

where i put this script ? in Server.cfg?

just dont add client_scripts

Dope suggestions… I appreciate the attention to detail in this post.

1 Like

thanks

VERY good post but most server owners are incompetent and can’t add that code without breaking something else.

1 Like

speak for yourself

About this. I think I know what you’re talking about but not 100%. Does not using client_scripts in the fxmanifest.lua but instead using files and internally loading the client scripts mean the client scripts are harder to read by a cheater? Please let me know if not but I would assume if we load them via files and do some encryption/decryption when loading we can make the client scripts harder to read?

Purelevel will also deny custom sound packs, graphic packs etc.

Doesn’t matter, anything and everything loaded by the client should be considered vulnerable by default. Use proper checks and don’t trust the client with anything it may manipulate instead of “encryption”, which is useless due to bytecode and other means of reading code anyway

2 Likes

I understand the client is ALWAYS vulnerable but I have previously seen a cheater dump a specific server and all the client scripts were using a custom encryption method which made all the client scripts no use to the cheater. This is what I was talking about, I know the client is always vulnerable but with custom encryption methods maybe it’s a good choice for the typical cheater joining your server

It might discourage a “typical cheater”, aka a script kid, but it wont discourage anyone determined. Again, the time and effort you spend on trying to encrypt your client-side code (assuming it somehow bypasses internal FiveM restrictions on these things, too, btw) would be better spent at simply writing more secure code, with server-side checks for anything abusable

1 Like

This is just security through obscurity, yes it will protect your scripts from potential script kiddies executing random events but at the end of the day the code is still executed on the client-side and will always be retrievable or at least its bytecode.

And even if you slap a super big custom obfuscated virtual machine onto your client-side script, it still isn’t anything secure since if someone really wants to, they can just read events that are being sent from and to the server and manipulate them how they want. I’m also not a big fan of most of those obfuscators since they all will have overhead and a huge performance hit when abused.

As @_4iY said, writing more secure code should be your biggest priority.

1 Like