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:
[QUOTE=WolfNinja2;43613288]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:[/QUOTE]
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
:/
Put it in a serverside file, not a shared.
Use Net Messages.
[url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Put this in a shared file:
[CODE]
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
[/CODE]
[QUOTE=Deathyy;43613966]Put it in a serverside file, not a shared.[/QUOTE]
Yes
[QUOTE=Fortune11709;43614011]Use Net Messages.
[url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url][/QUOTE]
No
[QUOTE=CallMePyro;43614230]Put this in a shared file:
[CODE]
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
[/CODE][/QUOTE]
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.
[QUOTE=Netheous;43615081]
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.[/QUOTE]
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
Sorry, you need to Log In to post a reply to this thread.