Adding table values through functions then reading them on client not working

Hi, I have been coding my addon for a while and I have come across a problem I didn’t think of.
After reloading the map / restarting the server, when it loads up non of the values “add” like when a player spawns it sets the players nwstring to something, then the client reads that and process’s it through the shared table.

The shared table values are added through a function…
These are basically snippets, but it explains how it works, and please dont judge my syntax thanks.
– default_abilities.lua


AddAbility( {  
	name = "Blink",
	color = Color( 25,100,100 ),
	cooldown = 10,
	material = "",
	ultimate = false,
	func = function(ply) 	
		ply:SetFOV( 150, 1 ) 
		ply:Freeze( true )

		timer.Simple(1.1,function() 
			ply:Freeze( false )
			ply:SetPos( ply:GetEyeTrace().HitPos )
			ply:SetFOV( 0, 1 ) 

			UnstuckPlayer( ply )
		end) 
	end
} )

– abilities.lua (shared)


Abilities = {}

function AddAbility( tab )
	if not istable( tab ) then Error( "You cannot create an ability without ability info" ) return end
	
	for k,v in pairs( Abilities ) do
		if (v["name"] == tab["name"]) then
			table.remove(Abilities, k)
		end
	end

	table.insert( Abilities, tab )		
end

hook.Add( "PlayerSpawn", "AbilitySet", function(ply)
	ply:SetNWString( "Ability1", "Blink" )
	ply:SetNWString( "Ability2", "Bounce" )
	ply:SetNWString( "Ability3", "Drop" )
	ply:SetNWString( "Ability4", "Cloak" )
end )

– cl_abilities.lua


if CLIENT then
      local function AbilityMenu()
		local Frame = vgui.Create( "DFrame" )
		Frame:SetSize( 350, 500 )
		Frame:Center()
		Frame:MakePopup()
		Frame:SetTitle( "Ability Selection Menu" )

		local List = vgui.Create( "DIconLayout", Frame )
		List:SetSize( Frame:GetWide() - 10, 80 )
		List:SetPos( 7.5, 25 )
		List:SetSpaceY( 5 ) 
		List:SetSpaceX( 5 )

		for i=1,4 do
			for k,v in pairs( GetAbilities() ) do
				if v[1] == i then
					local label = vgui.Create( "DLabel", List )
					label:SetSize( List:GetWide()/4 - 5, 75 )
					label:SetText( "" )
					label.Paint = function( self )
						if v[2]["material"] != "" then
							surface.SetDrawColor( 255,255,255,255 )
							surface.SetMaterial( Material( v[2]["material"] ) )
							surface.DrawRect( 0,0,self:GetWide(),self:GetTall() )
						else
							draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),v[2]["color"])
						end
						draw.SimpleText("Ability"..tostring(v[1]),"Trebuchet24",self:GetWide()/2,0,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)
						draw.SimpleText(tostring(v[2]["name"]),"DermaDefault",self:GetWide()/2,25,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)
					end
				end
			end
		end

		local Scroll = vgui.Create( "DScrollPanel", Frame )
		Scroll:SetSize( Frame:GetWide() - 5, Frame:GetTall() - 115 )
		Scroll:SetPos( 5, 110 )

		local AList = vgui.Create( "DIconLayout", Scroll )
		AList:SetSize( Scroll:GetWide() - 10, Scroll:GetTall() )
		AList:SetSpaceY( 5 ) 
		AList:SetSpaceX( 5 )

		local currentabils = {}

		for i=1,4 do
			table.insert( currentabils, ply:GetNWString( "Ability"..tostring(i) ) )
		end

		for k,v in pairs( Abilities ) do
			if not table.HasValue( currentabils, v["name"] ) then
				local label = vgui.Create( "DButton", AList )
				label:SetSize( List:GetWide()/4 - 5, 75 )
				label:SetText( "" )
				label.Paint = function( self )
					if v["material"] != "" then
						surface.SetDrawColor( 255,255,255,255 )
						surface.SetMaterial( Material( v["material"] ) )
						surface.DrawRect( 0,0,self:GetWide(),self:GetTall() )
					else
						draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),v["color"])
					end
					draw.SimpleText(tostring(v["name"]),"Trebuchet24",self:GetWide()/2,self:GetTall()/2,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
				end

				label.DoClick = function()
					local FFrame = vgui.Create( "DFrame" )
					FFrame:SetSize( 350, 400 )
					FFrame:Center()
					FFrame:MakePopup()
					FFrame:SetTitle( "Ability Binding Window" )

					local List = vgui.Create( "DIconLayout", FFrame )
					List:SetSize( Frame:GetWide() - 10, Frame:GetTall() - 10 )
					List:SetPos( 7.5, 25 )
					List:SetSpaceY( 5 ) 
					List:SetSpaceX( 5 )

					local label = vgui.Create( "DLabel", List )
					label:SetSize( List:GetWide() - 5, 50 )
					label:SetText( "" )
					label.Paint = function( self )
						draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color( 150,150,150,150 ))
						draw.SimpleText("Select an ability slot","Trebuchet24",self:GetWide()/2,25,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
					end

					for i=1,4 do
						local bind = vgui.Create( "DButton", List )
						bind:SetSize( List:GetWide()/2 - 5, 75 )
						bind:SetText( "Ability "..tostring(i) )

						bind.DoClick = function()
							RunConsoleCommand( "Ability"..tostring(i), tostring(v["name"]) )
							FFrame:Remove()
						end
					end
				end
			end
		end
	end
end

If I save the files, shared, default_abils then client it will saved the abilities, I can view them, use them, it adds them to the table. If I load up the map, nothing happens, like the tables don’t get inserted?

Do you know how to fix this issue?

Anyone understand why it isnt loading?

The addon loads, but the table doesnt update until I force it too …


(User was banned for this post ("Dumb Bump" - Nookyava))

Maybe try

include on default_abilities.lua with the file being abilities.lua, and the same thing but in reverse for the other file?

My guess is one of those files is being loaded before the other, but I haven’t read the code very thoroughly yet

I agree, but all that is wrong now is client to server and server to client is not working (only after I save the client folder it works), so you know?

Make sure you are including the shared file in your clientside init. Also make sure you are using AddCSLuaFile on your shared file in your serverside init.

It all works fine now, but another problem…
– server


function PlayerMeta:GetAbilities()
	local abil = {}

	for k,v in pairs( Abilities ) do
		for i=1,4 do
			if v["name"] == tostring(self:GetNWString( "Ability"..tostring(i) )) then
				table.insert( abil, { i, v } )
			end
		end
	end

	return abil
end


include( "abilities.lua" )

if CLIENT then
	surface.CreateFont( "AbilityKeyFont", {font = "Times New Roman",extended = false,size = 50,weight = 1000,blursize = 0,scanlines = 0,antialias = true,underline = false,italic = false,strikeout = false,symbol = false,rotary = false,shadow = false,additive = false,outline = false,} )
	surface.CreateFont( "AbilityFont", {font = "Times New Roman",extended = false,size = 25,weight = 1000,blursize = 0,scanlines = 0,antialias = true,underline = false,italic = false,strikeout = false,symbol = false,rotary = false,shadow = false,additive = false,outline = false,} )
	
	local ply = LocalPlayer() or {}

	local function AbilityPressThink()
		local nums = {}
		local abil = ply:GetAbilities()

		for i=1,4 do
			table.insert( nums, { i, (ply:GetNWInt( "Ability"..tostring(i).."Key" ) or 0), abil*[2]["cooldown"] } )
		end

		for k,v in pairs( nums ) do
			if ply:GetNWBool( "AbilityShifting" ) then
				if input.IsKeyDown( v[2] ) and input.IsShiftDown() then
					net.Start( "AbilityPress" )
						net.WriteInt( v[1], 16 )
					net.SendToServer()

					if not timer.Exists( "CooldownAbility"..tostring(v[1]) ) then
						timer.Create( "CooldownAbility"..tostring(v[1]), v[3], 1, function() end )
					end
				end
			else
				if input.IsKeyDown( v[2] ) then
					net.Start( "AbilityPress" )
						net.WriteInt( v[1], 16 )
					net.SendToServer()

					if not timer.Exists( "CooldownAbility"..tostring(v[1]) ) then
						timer.Create( "CooldownAbility"..tostring(v[1]), v[3], 1, function() end )
					end
				end
			end
		end
	end

	hook.Add( "Think", "AbilityPressThink", AbilityPressThink )

-- Snippets --

In my 100% client file ^, but it says that the ply:GetAbilities() == nil,
now as you saw before in my shared / server file we have ply:GetAbilities(), and this time its all addcsluafile and included, but for some reason I HAVE TO save the client file every time someone joins just to reboot it, like if it loaded by no data then when I save it all the data is there? Like the client folder is getting called first?



[ERROR] addons/abilities/lua/autorun/cl_abilities.lua:9: attempt to call method 'GetAbilities' (a nil value)
  1. fn - addons/abilities/lua/autorun/cl_abilities.lua:9
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109


[editline]19th November 2017[/editline]

(Player meta is defined too)

[editline]19th November 2017[/editline]

How do you refresh a if CLIENT then? (If I dont have it my client folder thinks its server and it hurts my brain)