• LocalPlayer() Not Initiating Fast Enough?
    7 replies, posted
Hello everyone, Im messing around with some Lua, but its quite there is a quite annoying bug I cannot figure out. Ill start out with my code: cl_init.lua [CODE]DeriveGamemode("base") HudConfig = HudConfig or {} HudConfig.Name = LocalPlayer():Nick() HudConfig.PlayerModel = LocalPlayer():GetModel() [/CODE] There's a whole bunch of other garbage, but this is the main ones Im concerned about. Every time I start a new server (Im just running singleplayer, but also adding player slots to simulate server) It throws this errror: [CODE] [ERROR] gamemodes/dans-roleplay-framework/gamemode/cl_init.lua:11: attempt to call method 'Nick' (a nil value) 1. unknown - gamemodes/dans-roleplay-framework/gamemode/cl_init.lua:11 [/CODE] Now, after I load in, and make a slight change, and RE-SAVE the Lua file, everything goes back to normal, and it properly picks up LocalPlayer(). Now why im not saying "Not picking up Nick()" because the error would be the exact same with GetModel() if it came first. Its almost as if LocalPlayer() doesnt load fast enough on the initial startup. Any help is much appreciated. Thanks!
Either use a timer or an 'or' statement So like it's equal to nick or "", something like that [editline]16th September 2015[/editline] But yeah, LocalPlayer() is nil when clientside files initially load
[QUOTE=NiandraLades;48690904]Either use a timer or an 'or' statement So like it's equal to nick or "", something like that [editline]16th September 2015[/editline] But yeah, LocalPlayer() is nil when clientside files initially load[/QUOTE] You mean something like?: HudConfig.Name = LocalPlayer():Nick() or ""
[IMG]http://i.imgur.com/bVCR9zy.png[/IMG]
[QUOTE=NiandraLades;48690904]Either use a timer or an 'or' statement So like it's equal to nick or "", something like that [editline]16th September 2015[/editline] But yeah, LocalPlayer() is nil when clientside files initially load[/QUOTE] My Previous post does not work, I even tried curly brackets and such. No luck, how would I implement a 2-3 timer second to the players initial spawn?
timer's do not have to be inside a function, they can be set off seconds after a file has loaded
I would just use a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/InitPostEntity]GM/InitPostEntity[/url] hook if you just want to do something when LocalPlayer() will not return NULL.
Sorry, you need to Log In to post a reply to this thread.