Player List Help

Hey! I have a custom player list in my roblox game, however when the player leaves the game, the players bar thing (with the display name and username etc.) doesn’t go away unless the player respawns, can somebody help with that?

Script:

game:GetService(“StarterGui”):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local function updatePlayerList()
local playerCount = #game.Players:GetPlayers()
script.Parent.Players.Header.Title.Text = “Players (” … playerCount … “)”

for _, v in pairs(game.Players:GetPlayers()) do
	local playerLayout = script.Parent.Players.List:FindFirstChild(v.Name)
	if playerLayout then
		playerLayout:Destroy()
	end

	local j = script.Parent.Players.List.Player_Item:Clone()
	j.Parent = script.Parent.Players.List
	j.Visible = true
	j.Username.Text = "@" .. v.Name 
	j.DisplayName.Text = v.DisplayName
	j.Name = v.Name
	j.Avatar.Image = "rbxthumb://type=AvatarHeadShot&id=" .. tostring(v.UserId) .. "&w=180&h=180"

	local rank = v:GetRankInGroup(7683625)
	if rank >= 120 then
		local modIcon = j.ModIcon
		modIcon.Visible = true
		j.Username.Position = UDim2.new(0.032, 65,0.545, 0)
		j.DisplayName.Position = UDim2.new(0.032, 67,0.075, 0)
	else
		j.Username.Position = UDim2.new(0, 65, 0.52, 0)
		j.DisplayName.Position = UDim2.new(0, 67, 0.05, 0)
	end

	local hasModeratorRole = v:IsInGroup(7683625)
	if hasModeratorRole then
		local moderatorRank = v:GetRankInGroup(7683625)
		if moderatorRank == 120 then
			j.GameMod.Text = "Game Moderator"
			j.GameMod.Visible = true
		elseif moderatorRank >= 224 then
			j.GameMod.Text = "Game " .. v:GetRoleInGroup(7683625)
			j.GameMod.Visible = true
		else
			j.GameMod.Visible = false
		end
	else
		j.GameMod.Visible = false
	end

	if v.Team then
		j.TeamName.Text = v.Team.Name
	else
		j.TeamName.Text = "No Team"
	end
end

end

while true do
wait()
updatePlayerList()
end

5 Likes

One solution you can add above your wait statement is,

game.Players.PlayerRemoving:Connect(function(plr)
	script.Parent.Players.List:FindFirstChild(plr.Name):Destroy()
end)
2 Likes

Alright, I’ll try that right now.

1 Like

It worked, Thank you so very much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.