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

Changing localplayer's name to be the text of a textlabel issue?

The title explains most of it. I don't know why it's not working and it's bugging me that I can't figure it out. Something this simple just feels weird. I just don't know what I'm doing wrong so please tell me.

This is the error I'm getting: Players.Player1.PlayerGui.MainScreen.Info.MoneyValue:12: attempt to index global 'name' (a string value)

the code (Localscript):

repeat wait() until game.Players.LocalPlayer
----------------------------------------------------------------------------------------------------
--Insert VARIABLES Below
----------------------------------------------------------------------------------------------------
player = game.Players.LocalPlayer
money = script.Parent.MoneyStats
moneyvalue = script.Parent.Parent.Money
name = script.Parent.Name
stop = false
----------------------------------------------------------------------------------------------------

name.Text = player.Name

repeat wait()
	money.Text = "$$$ = " ..moneyvalue.Value
until stop == true

5 comments

0

Why two variables for 'script.Parent.Name'?

0

Whoops just noticed this, I don't know why.

0

Edited now but still not working.

0

Is "name" a GUI Object, or the parent's actual name?

0

the name variable is a textlabel

3 answers

✓ Accepted answer

So based on what you said about the Name TextLabel thing, Name is a property of script.Parent, since all Instances have names. Just change the name of the TextLabel, and fix the script like so, and you're good to go.

repeat wait() until game.Players.LocalPlayer
----------------------------------------------------------------------------------------------------
--Insert VARIABLES Below
----------------------------------------------------------------------------------------------------
player = game.Players.LocalPlayer
money = script.Parent.MoneyStats
moneyvalue = script.Parent.Parent.Money
name = script.Parent.TEXTLABELNAME --Name the TextLabel something different than "Name" and replace TEXTLABELNAME with it.
stop = false
----------------------------------------------------------------------------------------------------

name.Text = player.Name

repeat wait()
    money.Text = "$$$ = " ..moneyvalue.Value
until stop == true

1 comment

0

Yup that seems to work, thanks I see what the problem is now

I would like to add to what Discern said.

You could change the name of the TextLabel, but it's not completely necessary. There are multiple ways to get a child of an object via a string, so it won't think you're referring to a property.

1. Use brackets.

script.Parent["Name"]

2. Use FindFirstChild()

script.Parent:FindFirstChild("Name")

3. Use WaitForChild()

script.Parent:WaitForChild("Name")

Hope this fixes

repeat wait() until game.Players.LocalPlayer
----------------------------------------------------------------------------------------------------
--Insert VARIABLES Below
----------------------------------------------------------------------------------------------------
player = game.Players.LocalPlayer
money = script.Parent.MoneyStats
moneyvalue = script.Parent.Parent.Money
name = script.Parent.Name
stop = false
----------------------------------------------------------------------------------------------------

name.Value = player.Name -- 'name' is a StringValue, not a TextLabel ;) You can't use Text in StringValues since theres no such property.

repeat wait()
    money.Text = "$$$ = " ..moneyvalue.Value
until stop == true

Hope this helps! ~marcoantoniosantos3 If doesnt work tell me output

1 comment

0

Same issue as before, also I don't think value is a member of textlabel (Name is the textlabel)

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