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

My player list is not removing players, why is that?

I am creating a GUI playerlist of buttons with each player on each button. However, when a player leaves, their button is not removed and just stays there.

Here are the scripts:

Client:

onPlayer = game.ReplicatedStorage.OnPlayer
x = 0
y = 0.178
frame = script.Parent
children = frame:GetChildren()
buttonSize = UDim2.new(1, 0, 0.178, 0)

local function button(name, xPos, yPos, parent, textColor, backgroundColor)
	local button = Instance.new("TextButton")
	button.Parent = parent
	button.Text = name
	button.Position = UDim2.new(xPos, 0, yPos, 0)
	button.TextScaled = true
	button.Name = name
	button.Size = buttonSize
	button.BackgroundColor3 = backgroundColor
end

local function getIndex(tab, elem)
	for i = 1, #tab do
		if tab[i] == elem then
			return i
		end
	end
	
	return -1
end

local function decreaseCanvas()
	y = y - 0.178
	frame.CanvasSize = UDim2.new(0, 0, y, 0)
end

local function destroyAllButtons()
	for i = 1, #children do
		if children[i].ClassName == "TextButton" then
			children[i]:Destroy()
		end
	end
end

local function createList()
	x = 0
	y = 0.178
	frame.CanvasSize = UDim2.new(0, 0, 0, 0)
	local players = game.Players:GetPlayers()
	
	for i = 1, #players do
		button(players[i].Name, x, y, script.Parent, Color3.fromRGB(0, 0, 0), Color3.fromRGB(255, 255, 255))
		y = y + 0.178
		frame.CanvasSize = UDim2.new(0, 0, y, 0)
	end
end

onPlayer.OnClientEvent:Connect(function()
	destroyAllButtons()
	createList()
end)

Server:

onPlayer = game.ReplicatedStorage.OnPlayer

game.Players.PlayerAdded:Connect(function(player) 
	onPlayer:FireAllClients() 
end)

game.Players.PlayerRemoving:Connect(function(player)
	onPlayer:FireAllClients()
end)

1 answer

The problem is you're firing the same Remote Event for both the PlayerAdded and PlayerRemoving events without parameters, to change this, simply add a parameter or use two different Remote Events.

1 comment

0

I don't think I need parameters, im simply using the remote event to let the client know to redo the player list.

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