game.ReplicatedStorage.LeaveQueue.OnServerEvent:Connect(function(plr)
for index, name in ipairs(playersLookingForMatch) do
if name == plr then
table.remove(playersLookingForMatch, index)
print("Player left queue!")
end
end
end)
Output when the button is clicked:
hi
I tested this while the player was already in the queue and it doesn’t do the second print.
this used to be working yesterday, which is what I don’t understand. Yes, the thing I’m using is an array of the players currently waiting inside a queue.
Assuming you aren’t storing the player objects in the table, you need to do this: if name == plr.Name then
Currently, you’re checking if name (a string of the player’s name presumably) matches the player object. It’s obviously going to be the same as they’re different things. However, the name & the .Name property of the player object can match.
Also:
This isn’t how it works. ipairs is similar to pairs but when it finds an element in the array that is nil, it will stop whereas pairs won’t.
You should really use WaitForChild() for getting LeaveQueue.
Also, you don’t need to check every single one of a table’s members. You can instead do it like this:
if table.find(playersLookingForMatch, plr) then --Check if the player exists in the table
table.remove(playersLookingForMatch, table.find(playersLookingForMatch, plr)) --Remove the player from their spot
end