Hi, i want to request a playerlist that updates the beckground of the Template with the TeamColor in realtime , i mean when i change my team to update the background color with the TeamColor.

This is the template i made for the playerstats:

https://prnt.sc/qduu1r

Code:

--< variables

local players = game:GetService("Players")
local frame = script.Parent
local slots = frame.slots
local temp = frame.Template
local player = players.LocalPlayer

local players_table = {}

--< tween info:TweenPosition(endPosition, EasingDirection, EasingStyle, Time, Override)

local dir = "Out"
local style = "Quad"
local dur = 0.5

--< functions

local function teamcolor()
						local Team = player.Team
					slots:FindFirstChild(player.Name).BG.ImageColor3 = Team.TeamColor.Color	
					player:GetPropertyChangedSignal("Team"):Connect(function()
					slots:FindFirstChild(player.Name).BG.ImageColor3 = Team.TeamColor.Color	
					end)
end

local function cleanup(slot)
	
	-- repeat wait until the slot finishes tweening
	repeat
		wait()
	until slot.Position.X.Offset == 400
	slot:Destroy()
	
end

local function remove(leaving)
	
	-- check if a player is leaving
	if leaving then
	
		-- if so, delete dictionary entry 
		players_table[leaving] = nil
		-- tween player slot out
		local slot = slots:FindFirstChild(leaving)
		teamcolor()
		slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Offset), dir, style, dur, true)
		
		-- delete the slot once it finishes (coroutine)
		local cor = coroutine.wrap(cleanup)
		cor(slot)
		
	end
end

local function add()
	
	-- loop through players
	local chil = players:GetChildren()
	for c = 1, #chil do
	
		-- check if present in dictionary
		if players_table[chil[c].Name] == nil then
				
			-- add to dictionary
			players_table[chil[c].Name] = 1
			
			-- create a slot in the list
			local slot = temp:Clone()
			
				-- edit that slot
				slot.Name = chil[c].Name
				slot.Text = slot.Name
				slot.Parent = slots
		end
	end
end

local function adjust(leaving)
	
	-- add() and remove()
	add()
	remove(leaving)
	
	local count = 0
	-- loop through players_table
	for key, value in pairs(players_table) do
	count = count + 1
		-- find corresponding slots
		local slot = slots:FindFirstChild(key)
		teamcolor()
		local ypos = 30 + (40+2)*(count-1)
		slot:TweenPosition(UDim2.new(0, 0, 0, ypos), dir, style, dur, true)
		
	end	
			
end



--< events

-- player added event
players.PlayerAdded:connect(function()
	adjust(nil)
teamcolor()
end)

-- player removing event
players.PlayerRemoving:connect(function(leaving)
	adjust(leaving.Name)
end)

adjust()
teamcolor()








2 comments

1

no... post code or no help k bye

0

First , that's rude and second i'll edit the post and i'll add it