Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is this still the best way to find someone's character?

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?

1 comment

0

Try char = game.Players.LocalPlayer.Character. Otherwise, you make a script insert a LocalScript after the Character spawns with char = script.Parent.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.