local player = game.Players.LocalPlayer local character = player.Character local bg = Instance.new("BillboardGui") bg.Parent = player.PlayerGui bg.Adornee = character.Head bg.Active = true bg.AlwaysOnTop = true bg.Size = UDim2.new(1, 0, 1, 0) bg.StudsOffset = Vector3.new(0, 2, 0) local bgcopy = bg:Clone() bgcopy.Parent = character.Head local frame = Instance.new("Frame") frame.Parent = bg frame.Size = UDim2.new(1, 0, 1, 0) frame.BackgroundTransparency = 1 frame.BackgroundColor3 = Color3.new(1, 1, 1) frame.Active = true local framecopy = frame:Clone() framecopy.Parent = character.Head.BillboardGui local text = Instance.new("TextLabel") text.Parent = frame text.Position = UDim2.new(0.25, 0, 0.25, 0) text.Size = UDim2.new(.5, 0, .5, 0) text.BackgroundTransparency = 1 text.Text = (player.NamePl.Value) text.FontSize = "Size24" text.TextColor3 = Color3.new(255, 255,255) text.Active = true local textcopy = text:Clone() textcopy.Parent = character.Head.BillboardGui.Frame
I keep getting this error
Players.Player1.PlayerGui.LocalScript:6: attempt to index local 'character' (a nil value)
-I'm new to this, fyi.
Most likely it is caused by this script running before the Character loads (hence player.Character
is nil
and from there is your error). However, SlickPwner's solution is incorrect as Character
is not a child, but a property, of a Player object.
Unfortunately I don't think there's a one-line solution to this, but here is what we can do:
local player = game.Players.LocalPlayer while not player.Character do wait() end local character = player.Character
We just wait for player.Character
to not be nil
(note that this solution doesn't work for children since accessing them would cause an error; since Character
is a property accessing player.Character
when the property is nil
triggers no error)
I would assume because you're not waiting for the Character. Try this:
local character = player:WaitForChild("Character")