local player_1 = player.GetByID(args[1])--//--player_1:GodEnable() wont work?

Yeah, so I was doing some coding today when I came across a little error.

My code:

Server Side:



function EnableGod(ply, command, args, public)
	if ply:IsAdmin() then
		local player_1 = player.GetByID(args[1])
		player_1:GodEnable()
	else
		ply:PrintMessage( HUD_PRINTTALK, "You Don't Have Access to this command!")
	end
end

concommand.Add( "ucc2_god_enable", EnableGod)


Client Side:



button.DoClick = function ()
  RunConsoleCommand("ucc2_god_enable", PlayerID)
end


The Error:



TEST [lua/autorun/server/rb655_item_pickup_fix.lua][lua/autorun/server/ucc2_sv.lua]
TEST [lua/autorun/server/rb655_map_dupe_fix.lua][lua/autorun/server/ucc2_sv.lua]

[ERROR] lua/autorun/server/ucc2_sv.lua:61: attempt to call method 'GodEnable' (a nil value)
  1. unknown - lua/autorun/server/ucc2_sv.lua:61
   2. unknown - lua/includes/modules/concommand.lua:69




BTW, sorry I messed up the title!

player.GetByID(args[1]) is returning nil.
To clarify, player.GetByID() takes in player ID, not name, and it must be a number.

But it is a number, if I hardcode the ID, I get the same issue.

What hardcoded ID are you using?

This is a shot in the dark, but try tonumber(args[1]) … It’s possible that the arguments received are in string form, so it’d be trying to do player.GetByID(“1”) instead of the proper player.GetByID(1)

2 is the number I get after I restart my game and start a local server on initial launch.

First player is 1. ( “owner” of listen server )

with one it worked now I have to get this to work with correct IDs since it shows me 2 instead of 1



ply:UserID()


EDIT:
Converted to number and removed 1 now it works fine?..NOPE!

Use EntIndex instead of UserID.

Well, it seems like that sort of fixed the issue, I have only one (kind of) unreleated issue with it, if not I will make a new post about it, Thanks for your help!