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

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

Asked by
Bman8765 270 Moderation Voter
9 years ago

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
0
Why two variables for 'script.Parent.Name'? Perci1 4988 — 9y
0
Whoops just noticed this, I don't know why. Bman8765 270 — 9y
0
Edited now but still not working. Bman8765 270 — 9y
0
Is "name" a GUI Object, or the parent's actual name? Discern 1007 — 9y
0
the name variable is a textlabel Bman8765 270 — 9y

3 answers

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago

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
0
Yup that seems to work, thanks I see what the problem is now Bman8765 270 — 9y
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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")
Log in to vote
-1
Answered by 9 years ago

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

0
Same issue as before, also I don't think value is a member of textlabel (Name is the textlabel) Bman8765 270 — 9y

Answer this question