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

Localscript can't find StringValue?

Asked by
AshJack 15
8 years ago

In my game there is a localscript that assigns the value of a StringValue as the name of the player. The StringValue is stored inside a button, so it has instances in StarterGui and inside the PlayerGui of all players. Here is the code:

script.Parent.PlayerName.Value = game.Players.LocalPlayer.Character.Name

It runs absolutely fine in Roblox Studio, but when I play my game normally through Roblox Player, I receive this error in the developer console:

PlayerName is not a valid member of TextButton

What is causing this?

2
Try using script.Parent:WaitForChild("PlayerName").Value - Things don't load instantly. General_Scripter 425 — 8y
2
I'll second that, which is important when it's a LocalScript. User#6546 35 — 8y
0
Is reputation broken for anyone else? UniversalDreams 205 — 8y
0
Thank you, that fixed it. I would upvote you, but I don't have enough reputation yet. AshJack 15 — 8y
View all comments (2 more)
0
@UniversalDreams It's their april fools General_Scripter 425 — 8y
0
They got me xD User#11440 120 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago

Since this is in a local script use a WaitForChild as instances do not load immediately on the client. Your code should be:

script.Parent:WaitForChild("PlayerName").Value = game.Players.LocalPlayer.Character.Name
Ad

Answer this question