PlayerMeta on Addons - Can't include another var?

Hello guys. I’m trying to use this function on an addon that I’m creating



local PlayerMeta = FindMetaTable("Player")
-- the function will receive 5 as argument
function PlayerMeta:SetVoiceLimit(limite)
	print(limite) -- print 5
	self.LimiteVoz = limite
	print(self.LimiteVoz) -- print 0
end
function PlayerMeta:VoiceLimit()
	return self.LimiteVoz
end


I have no idea. but self.LimiteVoz never get 5 value. What am I doing wrong?
How Can I do to start self.LimiteVoz as 0?

Your code works for me



] lua_run_cl player.GetByID(1):SetVoiceLimit(5)
5
5
] lua_run_cl print( player.GetByID(1):VoiceLimit() )
5


unless your question is to default it to 0, in which case:

[lua]
function PlayerMeta:VoiceLimit()
return self.LimiteVoz or 0
end
[/lua]

And use that function instead of getting the value directly.

Also, if you call Set* on the SERVER, the CLIENT won’t know what the value is so you may need to network the data if others need to know about it.

If you want a super easy / lightweight networking system for “flags” / vars: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_networking_system/sh_basic_networking_and_data_system.lua.html

It only supports flags which can be public or private; categories are in the full-addon version which adds another layer so vars can be categorized.

Private flags are networked to entity owners [IF SET ON SERVER]( so private player vars are networked only to the player, for weapons self.Owner is the player holding the weapon… for vehicles, it is the driver, for other entities it looks for self.Owner ) while public vars are broadcast to everyone. If set on the client, then regardless of public or private they remain only on that client so clients can keep the data / reference the data without needing to ask the server each time it needs the var. The values only get networked when they change, so no spam either.

Use self:SetFlag( “VoiceLimit”, limite, true ); if you want it to be private and self:SetFlag( “VoiceLimit”, limite ); for public. to retrieve use: self:GetFlag( “VoiceLimit”, 0 ); for public with default of 0 and self:GetFlag( “VoiceLimit”, 0, true ); if you set it as private with default of 0…