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

Localscript can't find StringValue?

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?

6 comments

2

Try using script.Parent:WaitForChild("PlayerName").Value - Things don't load instantly.

2

I'll second that, which is important when it's a LocalScript.

0

Is reputation broken for anyone else?

0

Thank you, that fixed it. I would upvote you, but I don't have enough reputation yet.

0

@UniversalDreams It's their april fools

0

They got me xD

1 answer

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

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