Won't display text but no errors?

So I am making an info GUI that displays the player name and group rank + rank number.

The issue is that when I load into the game, I don’t see the text that is supposed to show up. I also don’t have any errors showing up about the text not showing up.

Code

Player Name

game.Players.PlayerAdded:Connect(function()
	repeat wait() until game.Players.LocalPlayer.Character
	local player = game.Players.LocalPlayer
	
	player.PlayerGui.Cash.InfoFrame.PlayerName.Text = player.DisplayName
	print("Loaded player name!")
end)

Group Rank and Role

game.Players.PlayerAdded:Connect(function()
	repeat wait() until game.Players.LocalPlayer.Character
	local player = game.Players.LocalPlayer
	local rank = player:GetRoleInGroup(11187872)
	local rolenumber = player:GetRankInGroup(11187872)
	
	if player:IsInGroup(11187872) then
		player.PlayerGui.Cash.InfoFrame.GroupRank.Text = rolenumber.." | "..rank
		print("Loaded player rank")
	end
end)

Is there something that I am doing wrong?

Why is the code inside PlayerAdded connections? You’re not doing anything that would actually require it and only chaging the text of TextLabels in the LocalPlayer's gui (and not forgetting to mention that the code is going to be repeated for every other player that is added).

By the way, PlayerAdded connections in local scripts do not fire when the LocalPlayer is added to the game (but will do for different players), this might be the reason why it doesn’t work.

Looks like you’re also needlesly yelding by repeating wait() until the LocalPlayer's character is not nil, considering how it’s not ever referenced or used anywhere else.

Alright! It turns out, you’re overcomplicating things. I have come up with a solution that I just tested in Studio. Using the names of things in the script, I replicated your GUI the best I could, although it doesn’t really matter.

Screen Shot 2021-08-05 at 1.30.47 PM
As you can see, all you need to do is insert a LocalScript into the InfoFrame, or somewhere else in the GUI.

Then, paste the following code into the script.

local player = game:GetService("Players").LocalPlayer
local gui = script.Parent

gui.PlayerName.Text = player.DisplayName

-- If a player is not in the group, they will automatically have a group rank of "Guest with a rank ID of 0."
gui.GroupRank.Text = tostring(player:GetRoleInGroup(11187872)).." | "..tostring(player:GetRankInGroup(11187872))

That’s it! This exact script worked for me. You do not need to wait for the character to load in, all you need is this simple script inside of the GUI.

Also, do keep in mind that if you put the script somewhere else, you’ll need to make sure that the gui variable is the parent of the labels you are trying to change. For example, if the script was located directly inside of the Cash ScreenGui:

local gui = script.Parent.InfoFrame

Let me know if this doesn’t work or you have any questions!

1 Like