Need Help With Networked Vars

Okay, I’m trying to build a “fight or build” system. The player types !build to enter build mode and !fight to enter fight mode. I’m trying to make it so players can’t pick up new weapons if they’re in build mode but I’ve got a problem. Here’s my code:



hook.Add( "PlayerInitialSpawn", "Initialise Variables", function( ply )
	ply:InstallDataTable()
	ply:NetworkVar("Int", 1, "BuildMode")
	ply:SetBuildMode(0)
end);


function RestrictWeapons( player, ent )
	print(player:GetBuildMode())
	return (player:GetBuildMode() == 0)
end
hook.Add( "PlayerCanPickupWeapon", "Restrict Weapons", RestrictWeapons )

function BuildFightMode(ply, text, team)
	if (text == "!build") then
		ply:StripWeapons()
		ply:Give("weapon_physgun")
		ply:Give("gmod_tool")
		ply:Give("gmod_camera")
		ply:GodEnable()
		ply:SetBuildMode(1)
		print(ply:GetBuildMode())
	elseif (text == "!fight") then
		ply:GodDisable()
		ply:KillSilent()
		ply:SetBuildMode(0)
	elseif (text == "!stuck") then
		ply:KillSilent()
	end
end
hook.Add("PlayerSay", "Build Fight Mode", BuildFightMode)


The problem is that even after typing !build, the value of ply:GetBuildMode() is nil.

Edit:
Oh, and by the way, I know I should be using a boolean instead of an integer. I changed it to integer when it wasn’t working to see whether that helped, but it didn’t.

I don’t know if player:GetBuildMode() is what you want. I would recommend using this:

and then when you want to tell what mode they’re in, use "GetNWBool( “mode” )

According to the wiki, that’s an outdated method. In fact, even 2 years ago it was considered a bad method (though I can’t remember why). However, I suppose it’s better than nothing so I’ll use that until I can fix the issue properly.

Don’t use network vars. Just set a variable to the player like so:

[lua]
ply.buildMode = 0 --When they type !fight
ply.buildMode = 1 --When they type !build
[/lua]

Then in the PlayerCanPickupWeapon hook just:
[lua]
return ply.buildMode == 0
[/lua]

And if you ever wanted to display on a HUD which buildmode the player is in then you could just send a message to the client using the net library when that variable is changed.

Thanks, man. I don’t know what I was thinking. I feel like an idiot now.