Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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?

0
Try char = game.Players.LocalPlayer.Character. Otherwise, you make a script insert a LocalScript after the Character spawns with char = script.Parent. Redbullusa 1580 — 9y

1 answer

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Ad

Answer this question