ply:SetNWInt() resets after a while

Okay, so in my addon, I want to set the networked integer “MLevel_level” on a player during initial spawn, this works. I want to change the variable, this works. However, after a while the variable resets to 0

Serverside



function MLevel_PlayerInit(ply)	
  ply:SetNWInt("MLevel_level", 0)
  ply:SetNWInt("MLevel_skill", 0)
end
hook.Add("PlayerInitialSpawn", "MLevelInitializePlayer", MLevel_PlayerInit)


Shared



local MLevel_SkillList = {"level","skill"}

// Admin Commands /////////////////////////////////////////////////////////////////////////////////////////////////////////

local function MLevel_IsSkill(skill)
	for k,v in pairs(MLevel_SkillList) do
		if v == skill then return true end
	end
	return false
end

local function MLevel_SetPlayerStat(ply, cmd, args)
	if not ply:IsAdmin() then return end
	local target 	= player.GetAll()[tonumber( string.Trim( args[1]))]
	local skill		=	string.Trim( args[2])
	local amount 	= tonumber(string.Trim(args[3]))
	if not MLevel_IsSkill(skill) then ply:ChatPrint("Invalid Skill Set") return end
	local past = target:GetNWInt("MLevel_level")

	target:SetNWInt("MLevel_"..skill, amount)
	print("Your level was "..past..", now it's "..target:GetNWInt("MLevel_level"))
end
concommand.Add("MLevel_Admin_SetPlayerStat", MLevel_SetPlayerStat)

// Admin Commands /////////////////////////////////////////////////////////////////////////////////////////////////////////


In Testing, after first spawning, it’s 0

http://images.akamai.steamusercontent.com/ugc/439449666525462007/537A43BDCE621201AA405E2919543FAA07068655/

After setting my level to 50 and waiting ~10 seconds, I find it was reset to 0 again

http://images.akamai.steamusercontent.com/ugc/439449666525462811/46EE924F0CB19CA6DE7AD103BD61D1481CBF065A/

Is this on a windows sever or linux server?

If it’s windows then any time you make a change to your code it will auto reload and the data you had before you saved will be lost.

It looks like you’re also trying to make a leveling system; here’s a nice tutorial for uou

http://forum.facepunch.com/showthread.php?t=1390994

It’s a windows server, but the data resets without making any changes to the code. I will look at that tutorial but I still need help.

Your command is running on the client, not the server, which is setting your nwint clientside. It will automatically revert to the server value periodically when you change it that way.