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

Does not change the text to players name?

Local Script

local LocalPlayer_ = game.Players.LocalPlayer:WaitForChild("Billboard"):WaitForChild("Text")

function display(player)
if LocalPlayer_ == game.Players.LocalPlayer:WaitForChild("Billboard"):WaitForChild("Text") then
		print("Working")
		Text.Text = "Welcome ".. player.LocalPlayer_
	else print("Failed")
end

game.Players.PlayerAdded:connect(display)

display(game.Players.LocalPlayer)

Above is my code for a BillboardGui, it does not work and I have tried troubleshooting. Any help would be appreciated.

1 comment

0

Line 06 - You never declared what the variable "Text" is

2 answers

✓ Accepted answer

There are several issues with your code.

First off, I would recommend naming your variables something a little closer to what they equal. For example, your variable LocalPlayer_ is equal to a GUI Text Object. Consider possibly changing the variable name to something like 'TextLabel'. This is just to make it neater and make more sense.

Next, a BillboardGui will not work when inside a player - they would only work when inside the player's character, or some other part. If you're looking to have a GUI on the player's screen, consider using a ScreenGui instead. If you're wanting to use the BillboardGui, you'll need it to be inside the player's character. You can find the player's character by using,

local character = game.Players.LocalPlayer.Character

The If statement inside function display(player) is not needed. You already defined LocalPlayer_ as game.Players.LocalPlayer:WaitForChild("Billboard"):WaitForChild("Text"). So there would be no point in checking to see if the variable is still exactly as you previously defined it.

You can not use Text.Text because there was no variable created previous to this line named Text.

On that same line, you're attempting to set the text to "Welcome ".. player.LocalPlayer_ This would literally mean, that inside the player, you are trying to find game.Players.LocalPlayer:WaitForChild("Billboard"):WaitForChild("Text"). The game itself can not exist within the player, because the player exists within the game.

You are firing the function display(player) twice. Both with game.Players.PlayerAdded:connect(display) and with display(game.Players.LocalPlayer)

You are missing an end. You only have one end for the If statement. You need another for the actual function.

Also, I usually stray away from useing PlayerAdded in a LocalScript, because I usually run into issues with it when it's not Server-Side.

Below I will link some Wiki pages that I believe will help you:

PlayerAdded

Functions

Example code to learn from:

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local TextLabel = character:WaitForChild("Billboard"):WaitForChild("Text")

function display(player)
	if TextLabel then
	        print("Success")
	        TextLabel.Text = "Welcome ".. player.Name
	    else
			print("Error: 'Text' is not a member of 'Billboard'")
	end
end

display(game.Players.LocalPlayer)

Though the above code will fully work, you need to study it, learn from it, and apply it. Do not just copy and paste, you won't learn that way and will make the same mistakes in the future. I hope this helps you.

If my answer has helped your or solved your problem, don't forget to upvote and confirm

2 comments

0

I appreciate this greatly, thanks!

0

No problem!

If it's simply a LocalScript, you shouldn't need all the extra checks you have. The GUI also needs to be Adorneed to something. Make the GUI a child of something else, your PlayerGui if only you should see it or your Character otherwise.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local head = character:WaitForChild("Head")
local bb_gui = player:WaitForChild("Billboard")
local label = bb_gui:WaitForChild("Text")
print("Everything loaded")

bb_gui.Adornee = head
Label.Text = "Welcome "..player.Name

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