Help with custom playerlist

Hello Developers,

I’m working on a custom playlist, similar to Murder Mystery 2. Although, I’ve run into a problem with displaying the playlist for multiple people, along with setting NameTag colors. Here’s my script, please let me know what I did incorrectly.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

local LocalPlayer = game.Players.LocalPlayer;
local leaderboard = script.Parent.Parent.playerlist;

local NameTags = game.ReplicatedStorage.GetModuleServer:InvokeServer("NameTags");

local LevelData = {};

function Updateleaderboard()	
	local PlayerTable = {};
	
	for _,Player in pairs(game.Players:GetChildren()) do
		if not LevelData[Player.Name] then
			local coinAmnt = game.Players:FindFirstChild(LocalPlayer.Name).Coins.Value
			if coinAmnt ~= nil then
				LevelData[Player.Name] = {};			
			end
		end;
		
	if LevelData[Player.Name] ~= nil then
		table.insert(PlayerTable, {
			Player = Player;
			LD = LevelData[Player.Name]
			});
		end;
	end
	
	for i,Table in pairs(PlayerTable) do
		
		local Player = Table.Player;
		
		if Player ~= nil then
			local NewLabel = script.PlayerLabel:Clone();
			NewLabel.Name = "Player" .. i;
			local LD = LevelData[Player.Name];
			
			local LeaderboardPlayer = leaderboard:FindFirstChild("Player"..i)
					
			if LeaderboardPlayer ~= nil then
				ldrbrdplr:Destroy()
			end
			
			local Prefix = ""
			
			local PlayerObj = Instance.new("ObjectValue", NewLabel);
			PlayerObj.Name = "PlayerObj"
			PlayerObj.Value = Player;			
			NewLabel.Text = " " .. Prefix .. Player.Name
			
			local Color = NameTags[ tostring(Player.userId) ];
			
		    if Color then
		  	       NewLabel.TextColor3 = Color; -- troubles with colors here
		    end
		
			NewLabel.Parent = leaderboard;
			
			if Player == LocalPlayer then
				NewLabel.TextStrokeColor3 = Color3.new(15/255,15/255,15/255);
			end
			wait(1)
			Updateleaderboard()			
		end		
	end	
end

Updateleaderboard()
1 Like

Please post a gif / screenshots or an explanation of what goes wrong, that makes it a lot easier for us to find out where your code goes wrong.

So, for example, say that Player1 and Player2 join, and I am Player1. For the local player, there will be two slots with the name “Player1”

Are there errors?

Also this part you might as well just use the LocalPlayer instead of a :FindFirstChild() with its name on it. If the local player wasn’t found for example you would just be indexing nil.Coins.Value so the line looks contradictory.

Okay I’ll try this out in a little bit and let you know if it fixes anything. But there were no errors.