Still have questions? Join our Discord server and get real time help.
0

# How do I add players to a table when they click a button?

So I am making a minigame inside of a game. When the player clicks a button, I want them to be put into a folder/list/table etc. that will keep track of who is in the queue for minigames. Here is what I have:

local p = game.Players.LocalPlayer
local minigamePlayers = {}

script.Parent.MouseButton1Click:Connect(function()
table.insert(minigamePlayers,p)
end)

print(minigamePlayers)

script.Parent.MouseButton2Click:Connect(function()
table.remove(minigamePlayers,p)
end)

print(minigamePlayers)


The problem is the table never gets printed and I get an error when I right click: 18:02:59.315 - Players.tiller0831.PlayerGui.MB.TextButton.LocalScript:11: invalid argument #2 to 'remove' (number expected, got Instance)

0

Im gonna try my best to explain. instead of inserting just p into the table, insert p.Name, then to remove player do "#p.Name".

Solution:

local p = game.Players.LocalPlayer
local minigamePlayers = {}

script.Parent.MouseButton1Click:Connect(function()
table.insert(minigamePlayers,p.Name)
print(minigamePlayers)
end)

script.Parent.MouseButton2Click:Connect(function()
table.remove(minigamePlayers,#p.Name)
print(minigamePlayers)
end)