Calling a clientside variable from serverside function

Hello world !

This is my clientside code


	CreateCharacter = vgui.Create( "DButton", NewCharacter )
	CreateCharacter:SetText( "Creer un nouveau personnage" )
	CreateCharacter:SetTextColor( Color( 255, 255, 255, 200 ) )
	CreateCharacter:SetPos( 120, 500 )
	CreateCharacter:SetSize( 160, 30 )
	CreateCharacter.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 17, 28, 64, 240 ) )
	end
	CreateCharacter.DoClick = function ()
		local LastNameEntry = LastNameTextEntry
		local FirstNameEntry = FirstNameTextEntry
		local AgeEntry = AgeTextEntry
		local var = GetGlobalFloat("LastNameEntry")
		RunConsoleCommand("addcharacter")
	end

This is my function serverside where I would like to call for example LastNameEntry that is a variable from cl_init.lua


include("config/database.lua")

function newplayer()

	local preparedQuery = db:prepare("INSERT INTO `characters` (`id`, `nom`, `prenom`, `age`, `description`, `date`) VALUES (?, ?, ?, ?, ?, CURRENT_DATE())")
	function preparedQuery:onSuccess(data)
		print("Ligne insérée avec succès !")
	end

	function preparedQuery:onError(err)
		print("Une erreur est survenue lors de l'execution du query : " .. err)
	end
	
	local LastNameEntry = LastNameEntry

	preparedQuery:setNull(1)
	preparedQuery:setString(2, LastNameEntry)
	preparedQuery:setString(3, "Angel")
	preparedQuery:setNumber(4, 16)
	preparedQuery:setString(5, "Blond aux yeux bleus")

	preparedQuery:start()
	
end

concommand.Add( "addcharacter", newplayer )

And this is the error I get, but it’s because addcharacter.lua doesn’t know the variable LastNameEntry.


[ERROR] gamemodes/4realrp/gamemode/addcharacter.lua:17: bad argument #2 to 'setString' (string expected, got nil)
  1. setString - [C]:-1
   2. unknown - gamemodes/4realrp/gamemode/addcharacter.lua:17
    3. unknown - lua/includes/modules/concommand.lua:54


Thank you for your help,
Hippomino

You can’t interact with clientside elements on the server. You need to send the data in the derma.