SetNWInt error.

test/gamemode/cl_init.lua:41: attempt to call method ‘SetNWInt’ (a nil value)

What’s causing this? I can’t seem to find out why. If so how do you fix it?

post the lua in cl_init.lua at line 41, so we can tell you what’s wrong

Why are you setting a NWInt on the client?

I think he thinks that’s the way to share variables between files. Use this

[lua]ply.Variable = 3[/lua]

instead of

[lua]ply:SetNWInt( “Variable”, 3 )[/lua]

in that case.

Why is that when I use ply.variable and change the value serverside it does not update clientside?

Because it is only set in the current Lua state which is either the server or client state.

hmm actually when I put print(self.ammo) in the weapons think function it is printing 2 values. The value that I first set it and the current ammo

so its like

11
10
11
10
11
10

And if I shoot again it does

11
9
11
9
11
9

Why does it do that?

Because you’re doing it wrong.

Some source would really help.

Also thread hijacker

function SWEP:Initialize()
self.ammo=self.Primary.ClipSize
end

function SWEP:PrimaryAttack()
self.ammo=self.ammo-1
end
function SWEP:Think()
print(self.ammo)
end

Im not doing it wrong because it works just fine if I use SetNWInt().

You do know the SWEP system handles ammo itself.

Yes I am very aware of that…, but I’m making a game mode and if I use the ammo like that and the gun runs out of ammo you can’t switch to the weapon. And the game mode requires you to be able to switch to a empty weapon.