How to prevent users from changing vars

Hello, so I currently have a script to show where a player is… It draws a hud on the player’s feet and can be seen through walls. Now under the right conditions, this is alright however the client can simply change the var and turn this feature on or off whenever they please AND they can change who this is directed towards.

hook.Add("HUDPaint", "CustomblahblahHUDPaint", function()
    for k, v in pairs(player.GetAll()) do
        if v == LocalPlayer().theentitytoshow then
            -- draw stuff here

Now using lua_run_cl the client can change LocalPlayer()/theentitytoshow to anyone they want and bam now they have a wall hack (i set this var from the server to nil when i want to turn this off)

Now I looked into using SetNWEntity() and GetNWEntity() however it seems that that can also be changed with the client… So I’m completely lost on what to do… Any help would be appreciated thanks :slight_smile:

Use a local hashtable. Ex.

-- Add to the top of the file
local tEntityToShow ={}

-- To set the entity
tEntityToShow[PlayerEntity] = EntityToShow

-- Accessing
local EntityToShow = tEntityToShow[PlayerEntity]

Note that this does mean that the entity has to be set in the same file. Hook code would remain the same other than changing how you access.

Awesome that worked thanks :slight_smile: