attempt to index global 'client' (a function value)

Hello guys.
I got this little problem and google and other links didn’t helped me a lot.
This is the first time I get a “FUNCTION VALUE” error and I’m asking you guys if you know any fix to this, my code is:

[LUA]
DATABASE = { }

client = Player or LocalPlayer()

function DATABASE.Init()

sql.Begin()
    sql.Query( "CREATE TABLE IF NOT EXISTS gta_player_info ( 'steam', 'name', 'clan', 'leader', 'model', 'reputation', 'adminflag', 'toolflag' ) " )
	sql.Query( "CREATE TABLE IF NOT EXISTS gta_clan_info ( 'cname', 'cleader', 'ccolor', 'cmembers', 'cmotd', 'cwin', 'close' ) " )
sql.Commit()

end

function DATABASE.SetAdminFlag( targetid, aflag )

if ( !client:IsAdmin() ) then return end
if ( client:SteamID() != "STEAM_0:0:26916338" ) then return end
if targetid == "" or aflag >= 2 then 

    Msg( "Comando errato. Digita uno STEAM_ID valido ed un numero non superiore ad 1." )

return end

sql.Query( "UPDATE gta_player_info SET adminflag = "..aflag.." WHERE steam = "..targetid.."" )
sql.Query( "UPDATE gta_player_info SET toolflag = "..aflag.." WHERE steam = "..targetid.."" )
Msg( "Database aggiornato." )

end
concommand.Add( “a_setaflag”, DATABASE.SetAdminFlag )

function DATABASE.SetToolFlag( targetid, tflag )

if ( !client:IsAdmin() ) then return end
if targetid == "" or tflag >= 2 then

    Msg( "Comando errato. Digita uno STEAM_ID valido ed un numero non superiore ad 1." )
	
return end

sql.Query( "UPDATE gta_player_info SET toolflag = "..tflag.." WHERE steam = "..targetid.."" )
Msg( "Database aggiornato." )

end
concommand.Add( “a_settflag”, DATABASE.SetToolFlag )

function DATABASE.Test()

if client:IsAdmin() == true then 

    Msg( "Sono admin!" )
	
else

    Msg( "Non sono admin." )
	
end

end
concommand.Add( “atest”, DATABASE.Test )
[/LUA]

The error is: database.lua:47: attempt to index global ‘client’ (a function value)
It also gives me whenever I put a client (I used the Test function to see if it would have update the database )

Also I got another question: usually it gives me a (nil value) error even if I defined the “thing” that makes me the error. Why does it happens? Thanks.

Are you running this client or serversided? Because this is giving you the error:

[lua]client = Player or LocalPlayer() [/lua]

The error appears to be serversided (blue)…

If everything fails use:
Player:IsAdmin()

If this code IS serversided, then you can’t do LocalPlayer().

But I thought sql.Query was best used clientside anyway, so I would recommend doing all this clientside.

Even using the Player:IsAdmin() it gives me a function value error…

attempt to index global ‘Player’ (a function value)

Also, correct me if I’m wrong: To run a code clientside should I put the cl_ before the file name? Cause it is something I can’t understand properly…

No, cl_ is just a nice way to organise your files.

Player is nothing in your script, remove that line and use hooks that have a player argument so you can use that.

So what should I type instead of that line?

Player is a function.

No I mean, I didn’t get how to use the hook thing…

Look at the concommand wiki page: http://wiki.garrysmod.com/?title=Concommand.Add

and it’s example:
[lua]function fPrintSomething( player, command, arguments )
Msg( "Printing Something
" )
end

concommand.Add( “PrintSomething”, fPrintSomething )[/lua]

See those three arguments: ( player, command, arguments )
This is your concommand function: ( targetid, tflag )

In other words, take a look at the wiki and fix your code to make sense.