Custom Player List Bug

I made a custom player list that supports teams yet when I change teams for one player it shows that they changed teams yet on the second player/other plays it doesnt show them moved to the different team spot

There are no errors

Local Script:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local uis = game:GetService("UserInputService")
local Localplayer = Players.LocalPlayer

local background = script.Parent
local mainFrame = background:WaitForChild("MainFrame")
local template = script.Template
local _teams = {}

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

for i, team in pairs(Teams:GetChildren()) do
	_teams[team.Name] = i
end

local function refresh()
	for _, obj in pairs(mainFrame.ScrollingFrame:GetChildren()) do
		if obj:IsA("ImageLabel") then
			obj:Destroy()
		end
	end
	
	for _, team in pairs(Teams:GetChildren()) do
		if team:IsA("Team") then
			local teamTemplate = template:Clone()
			teamTemplate.Name = team.Name
			teamTemplate.ScrollingFrame.PlayerTemplate.Visible = false
			teamTemplate.Parent = mainFrame.ScrollingFrame
			teamTemplate.TeamName.Text = team.Name
			teamTemplate.LayoutOrder = _teams[team.Name]
		end
	end	
	
	template.ScrollingFrame.ChildAdded:Connect(function(child)
		if child:IsA("Frame") then
			template.ScrollingFrame.CanvasSize = UDim2.new(0, 0 , template.ScrollingFrame.CanvasSize.Y + 0.1, 0)
		end
	end)
	
	template.ScrollingFrame.ChildRemoved:Connect(function(child)
		if child:IsA("Frame") then
			template.ScrollingFrame.CanvasSize = UDim2.new(0, 0 , template.ScrollingFrame.CanvasSize.Y - 0.1, 0)
		end
	end)

	
	for _, player in pairs(Players:GetPlayers()) do
		if player.Team then
			local playerTemplate = mainFrame.ScrollingFrame:FindFirstChild(player.Team.Name).ScrollingFrame.PlayerTemplate:Clone()
			playerTemplate.Name = player.Name
			playerTemplate.Template.Text = player.Name.." - ".. player.leaderstats.Kills.Value
			playerTemplate.Visible = true
			playerTemplate.Parent = mainFrame.ScrollingFrame:FindFirstChild(player.Team.Name).ScrollingFrame
		else
			mainFrame.ScrollingFrame:FindFirstChild(player.Team.Name).ScrollingFrame:FindFirstChild(player.Name)
		end
	end
end

uis.InputBegan:Connect(function()
	if uis:GetFocusedTextBox() then return end
	if uis.KeyboardEnabled and uis:IsKeyDown(Enum.KeyCode.Tab) then
		background.Visible = not background.Visible
	end
end)

Localplayer.leaderstats.Kills.Changed:Connect(function()
	if mainFrame.ScrollingFrame:FindFirstChild(Localplayer.Team.Name):FindFirstChild(Localplayer.Name) then
		mainFrame.ScrollingFrame:FindFirstChild(Localplayer.Team.Name):FindFirstChild(Localplayer.Name):Destroy()
		refresh()
	end
end)

Players.PlayerAdded:Connect(function(newPlayer)
	refresh()
	newPlayer:GetPropertyChangedSignal("Team"):Connect(function()
		refresh()
	end)
end)

Players.PlayerRemoving:Connect(function(removedPlayer)
	refresh()
end)

refresh()
Localplayer:GetPropertyChangedSignal("Team"):Connect(function()
	refresh()
end)

Help is appreciated.

Because it’s a localscript, use a script and remoteevents.

Just to make sure is it going to be Local β†’ Server or the other way around?

Server β†’ Local

As you can fire the event if a player joins, ever changes team, or leaves.

Ahh, got it alright. I appreciate it.

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