char=localplr.Character
I was working on a GUI and for the first few minutes I was testing it just fine but then I had a Studio update and it quit working.
Does anyone know what ROBLOX changed yesterday and if it affected Lua? And my original question still stands: would the line of code above still act as the best way to fetch a localplayer's character?
Yes, this is the best way.
You should be careful that .Character
isn't nil
-- while the character is loading, it will be.
You should wait until the .Character
has spawned; either using CharacterAdded
or just a simple while
or repeat
loop. I personally like
local player = game.Players.LocalPlayer repeat wait() until player.Character local character = player.Character
Though there are other, equivalent options.