Can't get simple code snippet to print/return someones steamID to work


local ply = FindMetaTable( "Player" )

function ply:ShortSteamID()

	local id = self:SteamID()
	
	print( id )
	
	return id
	
end

self:ShortSteamID()

This script is running only serverside. It doesn’t seem to work.

Getting this error here:


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/1943rp_hud/sv_hud.lu
a:16: attempt to index global 'self' (a nil value)
  1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/1943rp_hud/sv
_hud.lua:16
   2. include - [C]:-1
    3. unknown - gamemodes/darkrp/gamemode/libraries/simplerr.lua:445
     4. doInclude - gamemodes/darkrp/gamemode/libraries/fn.lua:80
      5. loadModules - gamemodes/darkrp/gamemode/libraries/modificationloader.lu
a:79
       6. fn - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:126
        7. unknown - addons/ulib/lua/ulib/shared/hook.lua:183

self is a nil value, you didn’t assign it anything and you aren’t in a metafunction.

Your only issue is that you called the function on self.

Call it on a player.

so would i just do like?:


local ply = FindMetaTable( "Player" )

function ply:ShortSteamID()

	local id = self:SteamID()
	
	print( id )
	
	return id
	
end

Player:ShortSteamID()

I’m clueless…

Should be as long as Player is pointing to an actual player object.

I put that in and it gives me this:


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/1943rp_hud/sv_hud.lu
a:14: attempt to index global 'Player' (a function value)
  1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/1943rp_hud/sv
_hud.lua:14
   2. include - [C]:-1
    3. unknown - gamemodes/darkrp/gamemode/libraries/simplerr.lua:445
     4. doInclude - gamemodes/darkrp/gamemode/libraries/fn.lua:80
      5. loadModules - gamemodes/darkrp/gamemode/libraries/modificationloader.lu
a:79
       6. fn - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:126
        7. Call - addons/ulib/lua/ulib/shared/hook.lua:183
         8. unknown - lua/includes/modules/gamemode.lua:35