Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my Playerlist dont work ? It don´t show the players.

So I have it in StarterGui The terms in quotation marks are the objects. The above are the names

? Playerlist
	  localScript "localScript
	? Frame "Frame"
		 slots "Folder"
		? TextLabel "Frame"
			ImageLabel "ImageLabel"
			ImageLabel "ImageLabel"
			TextLabel "TextLabel"
		Template "TextLabel"

That´s my Script:

--< variables

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

local players_table = {}

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

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

--< functions

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)
		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)
		
		-- tween slot positions
		local ypos = 30 + (25+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)
end)

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

--< setup

adjust()

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.