Player:SetArmor() nil?

This is my code.

ply:SetArmor(ply:Armor() + 25)

And it gives me an error that SetArmor is a nil value. This doesn’t make any sense. ply = LocalPlayer() way before this point. HELP! D:

You are trying to run a server side function on the client.

How can I communicate between server and client easily? Like is there a way to make just those run through server?

[editline]21st January 2014[/editline]

If i try putting it all in a shared the hud refuses to draw
:confused:

Put it in a serverside file, not a shared.

Use Net Messages.

Put this in a shared file:



if CLIENT then

	local function set_armor_from_client( armor )
		net.Start( "set_armor" )
			net.WriteInt( armor, 32 )
		net.SendToServer()
	end
	
else --Server

	util.AddNetworkString( "set_armor" )

	net.Receive( "set_armor", function( _, ply )
		ply:SetArmor( net.ReadInt( 32 ) )
	end )
	
end


Yes

No

No

He doesn’t need any networking. He wants to draw armor on hud, not set armor via clientside.
Especially not the way CallMePyro told him to as it’s easily exploitable.

So in other words: Leave HUD drawing functions in a clientside file or clientside part of shared.lua and move your ply:SetArmor() inside a serverside file or serverside part of shared.

I know it’s easily exploitable. I was simply providing him code that would let him set armor from the client. There’s a reason it’s not allowed on the client, and only on the server. I am very aware. If someone wants to create a gamemode where players will already be able to arbitrarily set their armor, then this function might be useful.

I thought that’s what he wanted, so that’s what I posted. He can use it or not, no harm done. It’s a good example of simple networking anyways, if he was interested.

Yes, I agree it’s a good example of networking, althought it’s unneccessary

Actually im trying to make abilities. So when the player clicks a button, a ability (like ply:SetArmor(ply:Armor() + 25) happens and then a cooldown happens. So I do need that networking stuff… haha