Error with IsAdmin

Hello I have this code:
[lua]
local ply = LocalPlayer()
if ply:IsAdmin() && ply:IsSuperAdmin() then
hook.Add( “HUDPaint”, “AdminCheck”, function()
surface.SetFont( “CenterPrintText” )
surface.SetTextColor( 0, 255, 94, 255 )
surface.SetTextPos( 225, 1050 )
surface.DrawText( “Admin” )
end )

else
return false

end
[/lua]

and I get this error even though I am an admin:

[lua]
[ERROR] gamemodes/life/gamemode/cl_init.lua:4: attempt to call method ‘IsAdmin’ <a nil vaalue>

  1. unknown - gamemodes/life/gamemode/cl_init.lua:4

[TheNeuraProject:2:STEAM_:0:0:XXXXXXXX] Lua Error:
Couldn’t Load Init Script: ‘life/gamemode/cl_init.lua’

[/lua]
Please help

Does IsAdmin exist clientside?

It is shared, so yes.

[editline]16th November 2014[/editline]

[lua]
if (LocalPlayer():IsSuperAdmin()) then
hook.Add( “HUDPaint”, “AdminCheck”, function()
surface.SetFont( “CenterPrintText” )
surface.SetTextColor( 0, 255, 94, 255 )
surface.SetTextPos( 225, 1050 )
surface.DrawText( “Admin” )
end)
end
[/lua]
No need for the “else return end” shit

I get another error:

[lua]
[ERROR] gamemodes/life/gamemode/cl_init.lua:4: attempt to call method ‘IsSuperAdmin’ <a nil vaalue>

  1. unknown - gamemodes/life/gamemode/cl_init.lua:4

[TheNeuraProject:2:STEAM_:0:0:XXXXXXXX] Lua Error:
Couldn’t Load Init Script: ‘life/gamemode/cl_init.lua’
[/lua]

LocalPlayer() doesn’t exist as soon as cl_init.lua is loaded. That’s why you get da errors.

Correct way of doing this would be:



hook.Add( "HUDPaint", "AdminCheck", function()
	if (!IsValid(LocalPlayer()) || !LocalPlayer():IsAdmin()) then return end -- If not admin, dont execute code below in this function
	surface.SetFont( "CenterPrintText" )
	surface.SetTextColor( 0, 255, 94, 255 )
	surface.SetTextPos( 225, 1050 ) 
	surface.DrawText( "Admin" )
end)


-snip-

Okay.
How do I do the same thing but with SteamID
[lua]
hook.Add( “HUDPaint”, “ID”, function()
surface.SetFont( “CenterPrintText” )
surface.SetTextColor( 255, 255, 255 )
surface.SetTextPos( 9, 1050 )
surface.DrawText( LocalPlayer():SteamID() )
end )
[/lua]

[editline]16th November 2014[/editline]

Thanks

[editline]16th November 2014[/editline]

Oh I think I got it

[lua]
hook.Add( “HUDPaint”, “ID”, function()
if (!IsValid(LocalPlayer())) then
surface.SetFont( “CenterPrintText” )
surface.SetTextColor( 255, 255, 255 )
surface.SetTextPos( 9, 1050 )
surface.DrawText( LocalPlayer():SteamID() )
end
end )
[/lua]
Right?


hook.Add( "HUDPaint", "ID", function()
    if (IsValid(LocalPlayer())) then
        surface.SetFont( "CenterPrintText" )
    surface.SetTextColor( 255, 255, 255 )
    surface.SetTextPos( 9, 1050 ) 
    surface.DrawText( LocalPlayer():SteamID() )
    end
end )

You code tries to draw the stuff if LocalPlayer is INVALID ( if ( ! IsValid ) then ), while you should be doing ( if ( IsValid ) then )

Ohhhh I see Thank you!!
!