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

Why is this giving me a "syntax" error?

I am trying to make a custom third person health bar (other people see it) I have it so that it makes the local players head the Adornee, which would then put the billboard gui above the players head... But it's saying that "player is not a valid member of Workspace"

Local player = game.Players.LocalPlayer:GetFullName()

script.Parent.Adornee = script.Parent.Parent.Parent.Parent.Parent.Workspace.player.Head

Please help Thank you!

20 comments

0

Try game.Workspace.player.Head

0

For starters your 1st line, your variable can't have a space in it...

0

Dafuq you talking about tanzane, nothing wrong with his first variable

0

For starters it's local player, if you don't know what your talking about, don't comment

0

@Discern- I tried that just now, it gave the same error!

0

Omg, no I mean if you're going to do a Local Keyword. Make sure it isn't cap'd. Stop acting like I was wrong...

0

Except you were, that wasn't even the error

0

It WOULD of been if I hadn't told you

0

Except that it WASNT even BEFORE you posted

0

Where is the script in your game?

0

It is in the player's gui

0

But it is originally in the starter gui

0

Is this a local script?

0

No, wait, then do script.Parent.Parent.Character.Head

0

I did that, but now nothing happens

0

Not even an error

0

What is the whole line of text?

0

I don't understand what you mean, of course it's text, what else could it be?

0

Show me the WHOLE script

0

That is the entire script

1 answer

That is not a syntax error.

A syntax error is when you are syntactically invalid -- that is, it doesn't care what you wrote, the "grammar" of it is wrong.


The error you're getting is a run time error -- an error that happens after the script starts running (it can't start running if it doesn't understand you -- a syntax error)


First: local must be lowercase.


:GetFullName() is not usually useful for scripts (i.e., it's only useful to humans). If you want a reference to an object, just use object itself, e.g.,

local player = game.Players.LocalPlayer

Now we want the player's Character. That will simply be

local character = player.Character

However, the Character won't load immediately. A simple way to do it is to wait() until you it's there:

repeat
	wait()
until player.Character
local character = player.Character

A more terse way to write it is

local character = player.Character or player.CharacterAdded:wait()

Now the character's Head is simply character.Head

Though it might be safer to wait for it to be there, hence, we could use

local head = character:WaitForChild("Head")
script.Parent.Adornee = head

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