Hello.
Excuse me for any grammatical errors.
I initialize a table called "weaponsTable" when the player spawns:
hook.Add("PlayerSpawn", "player_Spawn", function(ply)
ply.weaponsTable = {}
end)
In this table I want to save informations about the weapons of the player, this is the function:
function meta:saveWeapons()
for k, v inipairs(self:GetWeapons()) do
self.weaponsTable[k] = {v:GetClass(),v:Clip1(), v:Clip2()}
end end
But when I try to give the weapons saved in that table, I can't because for some reasons the table is not valid..
function meta:giveWeapons()
for _, v in pairs(self.weaponsTable) do
local weapon = self:Give(v[1])
self:RemoveAllAmmo()
weapon:SetClip1(v[2])
weapon:SetClip2(v[3])
end
end
Probably this is the wrong way to do it, can someone explain me the exact way?
Thank you!
The code looks fine, then most likely you call the giveWeapons () function before the table appeared.
I could help if you gave more code
I have just found the problem...
I was trying to call the function "giveWeapons()" after the player get spawned, when the table has just been initialized, to fix it i put the initialization of the table in another function.
Thank you!
Sorry, you need to Log In to post a reply to this thread.