ConVar resetting back to 1 and Player Models/Colors reset as well

I’m trying to make a ConVar where if you have it set to a certain mode it’ll change the model/color of the player. The player models and colors do not set, but also, the ConVar always resets back to 1 even if I put it into the autoexec.cfg Any ideas?

[lua]COLOR_YELLOW = Color(255, 255, 0)
COLOR_BLACK = Color(0, 0, 0)
COLOR_GREEN = Color(0, 255, 0)
COLOR_DGREEN = Color(0, 100, 0)
COLOR_RED = Color(255, 0, 0)
COLOR_WHITE = Color(255, 255, 255)
COLOR_LGRAY = Color(200, 200, 200)
COLOR_BLUE = Color(0, 0, 255)
COLOR_NAVY = Color(0, 0, 100)
COLOR_PINK = Color(255,0,255)
COLOR_ORANGE = Color(250, 100, 0)
COLOR_OLIVE = Color(100, 100, 0)

ALYX = “models/player/alyx.mdl”
GMAN = “models/player/gman_high.mdl”
BREEN = “models/player/breen.mdl”
BARNEY = “models/player/barney.mdl”
ELI = “models/player/eli.mdl”
GRIGORI = “models/player/monk.mdl”

CreateConVar( “test_playermodel”, “1”, { FCVAR_REPLICATED, FCVAR_ARCHIVE }, “type test_models for the models.” )
function ChoosePlayerModelTest( ply )
local mode = GetConVarNumber( “test_playermodel” ) or 0

if mode == 1 then ply:SetModel( GMAN )
elseif mode == 2 then ply:SetModel( ALYX )
elseif mode == 3 then ply:SetModel( BREEN )
elseif mode == 4 then ply:SetModel( BARNEY )
elseif mode == 5 then ply:SetModel( ELI )
elseif mode == 6 then ply:SetModel( GRIGORI )
end

end
hook.Add( “PlayerSetModel”, “TestPlayerModelBegin”, ChoosePlayerModelTest )

CreateConVar( “test_playercolor”, “1”, { FCVAR_REPLICATED, FCVAR_ARCHIVE }, “type test_colors for the colors.” )
function ChoosePlayerColorTest( ply )
local mode2 = GetConVarNumber( “test_playercolor” ) or 0

if mode2 == 1 then return COLOR_YELLOW
elseif mode2 == 2 then return COLOR_BLACK
elseif mode2 == 3 then return COLOR_GREEN
elseif mode2 == 4 then return COLOR_DGREEN
elseif mode2 == 5 then return COLOR_RED
elseif mode2 == 6 then return COLOR_WHITE
elseif mode2 == 7 then return COLOR_LGRAY
elseif mode2 == 8 then return COLOR_BLUE
elseif mode2 == 9 then return COLOR_NAVY
elseif mode2 == 10 then return COLOR_PINK
elseif mode2 == 11 then return COLOR_ORANGE
elseif mode2 == 12 then return COLOR_OLIVE
end

end
hook.Add( “TTTPlayerColor”, “TestPlayerColorBegin”, ChoosePlayerModelColorTest )[/lua]

You have created the convar for the server, not for each player. ( so it will be the same for every player once you change it )

If you don’t mind me asking, how exactly would I create it for the client? You don’t have to force feed, I just need a general idea. Thanks!

This should tell you everything you need.

Thank you, I appreciate the help.

[editline]13th March 2016[/editline]

Hey, I didn’t think about it at the time since I wasn’t home at that moment, but I might have worded it wrong, I want the server owner to be able to change the ConVar to change the models, but it still resets it back to 1 even if it’s in the autoexec.cfg, not so every player can set it themself. Sorry about the mix up. Also, do you have any ideas why the models or the player colors won’t work?

is the file server, or clientside?

server

Try removing the FCVAR_* from table.

I removed it and it still did not work, I just realized something though. With both the FCVAR’s and without when I first boot the server and I have the values in the autoexec.cfg

It shows

but if I go into the cmd on the console and type “test_playercolor” it gives me the default value of 1, any ideas?

that’s normal, the lua convars don’t get created until the lua state initializes and createconvar gets called. config files are ran before that.

Alright I had the wrong idea then, my bad. How do I make the models change though? The models won’t seem to change. The colors work fine, just not the model change.