• Trying to get Player's name and group
    9 replies, posted
Hello, I'm trying to make a derma panel, and I want to show the name and group of the player. I've made it so that the derma panel opens when the player join the server and when a command is typed. but I get this error : [ERROR] lua/autorun/client/data.lua:7: attempt to call method 'Name' (a nil value)   1. OpenCharacterMenuCl - lua/autorun/client/data.lua:7    2. func - lua/autorun/client/data.lua:2     3. unknown - lua/includes/extensions/net.lua:32 But it only happens when after connecting, but when i type the command ther is no error and the data is displayed. So, here is the hook I use: hook.Add( "PlayerInitialSpawn", "Spawn", function( player )     local name = player:GetName()     local rank = player:GetUserGroup()     local steamid64 = player:SteamID64()     local ip = player:IPAddress()       local Timestamp = os.time()     local time = os.date( "%H:%M:%S - %d/%m/%Y" , Timestamp )     WriteToFile( name, steamid64, rank, ip, time )     OpenCharacterMenu( player, rank )     connectToDatabase() end ) and the function: function OpenCharacterMenu( player )     net.Start( "OpenCharacterMenu" )     net.Send( player ) end and here is the clientside code: net.Receive( "OpenCharacterMenu", function()     OpenCharacterMenuCl() end ) function OpenCharacterMenuCl()     local Player = LocalPlayer()     local username = Player:Name()     local rank = Player:GetUserGroup()     local steamid = Player:SteamID()
instead of Player:Name() you should try to use Player/Nick
It doesn't work :/ [ERROR] lua/autorun/client/data.lua:7: attempt to call method 'Nick' (a nil value)   1. OpenCharacterMenuCl - lua/autorun/client/data.lua:7    2. func - lua/autorun/client/data.lua:2     3. unknown - lua/includes/extensions/net.lua:32
wait i just noticed. You are doing this net.Receive( "OpenCharacterMenu", function() OpenCharacterMenuCl() end ) but you are supposed to do this net.Receive( "OpenCharacterMenu", function() OpenCharacterMenuCl end ) Im pretty sure atleast. Been a while since i did Glua now, but i remember that you dont put () inside a function, to call a function
the function need the () or gmod die xD [ERROR] lua/autorun/client/data.lua:3: '=' expected near 'end'   1. unknown - lua/autorun/client/data.lua:0
Some functions like Nick or SteamID don’t exist till a certain point after the player has loaded in. I found the best way to overcome it is by running anything using it after GM/InitPostEntity is triggered clientside.
Returns the players name. Identical to Player:Nick and Player:GetName Player/Name
then why does the 3 different versions exist? Not to explain, i actually want to know. If they all 3 are identical?
Just to clarify it's because LocalPlayer returns NULL until GM/InitPostEntity
i feel like gmod could really profit from one HUGE cleanup. Getting rid of all old functions etc. That would mean that alot of older addons break tho so..probably wont happen
Sorry, you need to Log In to post a reply to this thread.