Hello, I am making a Overhead Gui is supposed to display the players Rank, from a leaderstat, but it doesn’t change the text.
The Script:
local billboardgui = game:GetService("ServerStorage"):WaitForChild("NameTag")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == game.Teams.Prisoners then
local Clone = billboardgui:Clone()
Clone.Name = player.UserId
Clone.Title.Text = player.Name
Clone.Title.TextColor3 = Color3.fromRGB(255, 128, 0)
Clone.Icon.Rank.Text = player:WaitForChild("leaderstats"):WaitForChild("Rank").Value
Clone.Parent = game.Workspace:WaitForChild(player.Name).UpperTorso
end
if player.Team == game.Teams.Police then
local Clone = billboardgui:Clone()
Clone.Name = player.UserId
Clone.Title.Text = player.Name
Clone.Title.TextColor3 = Color3.fromRGB(85, 170, 255)
Clone.Icon.Rank.Text = player:WaitForChild("leaderstats"):WaitForChild("Rank").Value
Clone.Parent = game.Workspace:WaitForChild(player.Name).UpperTorso
end
if player.Team == game.Teams.Criminals then
local Clone = billboardgui:Clone()
Clone.Name = player.UserId
Clone.Title.Text = player.Name
Clone.Title.TextColor3 = Color3.fromRGB(170, 0, 0)
Clone.Icon.Rank.Text = player:WaitForChild("leaderstats"):WaitForChild("Rank").Value
Clone.Parent = game.Workspace:WaitForChild(player.Name).UpperTorso
end
if player.Team == game.Teams.Heroes then
local Clone = billboardgui:Clone()
Clone.Name = player.UserId
Clone.Title.Text = player.Name
Clone.Title.TextColor3 = Color3.fromRGB(170, 170, 0)
Clone.Icon.Rank.Text = player:WaitForChild("leaderstats"):WaitForChild("Rank").Value
Clone.Parent = game.Workspace:WaitForChild(player.Name).UpperTorso
end
end)
end)
Were i change the Text when the player Ranks up (Also Doesn’t work)
local Player = game.Players:GetPlayerByUserId(script.Parent.Name)
Player:WaitForChild("leaderstats"):WaitForChild("Rank").Value.Changed:Connect(function(new)
script.Parent.Title.Text = new
end)
Player.Team.Changed:Connect(function(newTeam)
if newTeam == game.Teams.Prisoners then
script.Parent.Title.TextColor3 = Color3.fromRGB(170, 85, 0)
end
if newTeam == game.Teams.Police then
script.Parent.Title.TextColor3 = Color3.fromRGB(85, 170, 255)
end
if newTeam == game.Teams.Prisoners then
script.Parent.Title.TextColor3 = Color3.fromRGB(255, 0, 0)
end
if newTeam == game.Teams.Prisoners then
script.Parent.Title.TextColor3 = Color3.fromRGB(255, 170, 0)
end
end)
You shouldn’t be using :WaitForChild for something more than something added directly to the player. In fact you can probably replace both of them with FindFirstChild because I assume that leaderstats will already exist once you are trying to call upon it therefore it is going to infinitely yield. Just a recommendation don’t know if this will solve your issue.
One of the main issues I am seeing here is like what I said, You are using wayyy too many :WaitForChild() instead of :FindFirstChild()… Another thing is… Is this a Server Script or a LocalScript?
Player.Team.Changed:Connect(function(newTeam)
if newTeam == game.Teams.Prisoners then
script.Parent.Title.TextColor3 = Color3.fromRGB(170, 85, 0)
end
if newTeam == game.Teams.Police then
script.Parent.Title.TextColor3 = Color3.fromRGB(85, 170, 255)
end
if newTeam == game.Teams.Criminals then
script.Parent.Title.TextColor3 = Color3.fromRGB(255, 0, 0)
end
if newTeam == game.Teams.Civilians then
script.Parent.Title.TextColor3 = Color3.fromRGB(255, 170, 0)
end