Currently, I am making a list of players who want to play in the next game or not (Queues), in this system the user to press a physical object runs a RemoteEvent that adds it to a list of the queue, after running this RemoteEvent it runs another one that notifies all players in the game and updates the list in the GUI of all players, my error is that for some reason, the update of the list and the addition of the list only is executing it the last player that enters to the game, when the list executes FireAllClients only this one is receiving it and not the rest, here I leave a part of my code so that my problem is understood.
JoinScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JoinQueueEvent = ReplicatedStorage:WaitForChild("JoinQueueEvent")
local clickDetector = Instance.new("ClickDetector")
clickDetector.MaxActivationDistance = 100
clickDetector.Parent = script.Parent
clickDetector.MouseClick:Connect(function()
print("clicked")
JoinQueueEvent:FireServer()
end)
CreateQueue:
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Player = game:GetService("Players")
local JoinQueueEvent = ReplicatedStorage:WaitForChild("JoinQueueEvent");
local UpdateQueueEvent = ReplicatedStorage:WaitForChild("UpdateQueueEvent")
local queue = {}
local minPlayers = 3
local maxPlayers = 32
local countdownTime = 10
local function updateQueue()
UpdateQueueEvent:FireAllClients(queue)
end
local function addUser(player)
for _, queuedPlayer in ipairs(queue) do
if queuedPlayer == player then
print("Ya esta en la cola")
return
end
end
if #queue >= maxPlayers then
return
end
table.insert(queue, player)
updateQueue()
end
JoinQueueEvent.OnServerEvent:Connect(function(player)
print("new user :3")
addUser(player)
end)
GUIScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateQueueEvent = ReplicatedStorage:WaitForChild("UpdateQueueEvent")
local screenGui = script.Parent
local function UpdateGUI(players)
print(players)
for _, child in ipairs(screenGui:GetChildren()) do
child:Destroy()
end
for i, usuario in ipairs(players) do
local imagenPerfil = Instance.new("ImageLabel")
imagenPerfil.Size = UDim2.new(0, 100, 0, 100)
imagenPerfil.Position = UDim2.new(0, i * 110, 0, 0)
imagenPerfil.Image = "rbxthumb://type=Avatar&id=" .. usuario.UserId .. "&w=150&h=150"
imagenPerfil.Parent = screenGui
end
end
UpdateQueueEvent.OnClientEvent:Connect(UpdateGUI)