Why does this text changing script for a SurfaceGui not work?

I’m trying to make a script so that when a player holds out a tool, it changes the text on the tool to the username of the person holding it, but I am getting an error. I have attempted to do this within a local script inside StarterPlayerScripts;

game.Players.LocalPlayer.Backpack:WaitForChild("AccountInfo")
game.Players.LocalPlayer.Backpack.AccountInfo.Handle.SurfaceGui.UsernamePerson.Text = game.Players.LocalPlayer.Name

image
But then, it says that “Backpack is not a valid member of player” in the output. How do I fix this?

add a
game.Players.LocalPlayer:WaitForChild("Backpack")

1 Like

Now it gives


and it still doesn’t show the person’s username on the surface gui?

If the tool is equipped, it moves over to the player’s character model, so you can do something like:
game.Players.LocalPlayer.CharacterAdded:Wait()
local tool = game.Players.LocalPlayer.Backpack:WaitForChild("AccountInfo") or game.Players.LocalPlayer.Character:WaitForChild("AccountInfo")
tool.Handle.SurfaceGui.UsernamePerson.Text = game.Players.LocalPlayer.Name

2 Likes

It works now, thanks so much!

30 char

1 Like

No problem, hope you have a fun time developing

1 Like