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?
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