Let me just show you my script before I ask:
local debounce = true local ExampleTable = {} -- open for players names to be put in script.Parent.Touched:Connect(function(player) if not debounce then return end debounce = false if not ExampleTable[player.Parent.Name] then print("Player is not in table") table.insert(ExampleTable, player.Parent.Name) wait(1) debounce = true else print("Player's name is in table") table.remove(ExampleTable, player.Parent.Name) wait(1) debounce = true end)
Everytime I touch the brick, it tells me over and over that it is not in the table.
Is my table.insert is wrong or what? Should I even use this?
To test if a argument is on a Table, you must use TABLE[1 ~ #TABLE]
Change the "1 ~ #TABLE" to a number(of the argument you want to get)
Example:
TestTable = {"Leamir", "Is A Noob"} print(TestTable[2]) -- This will print "Is A Noob"
But, if you want to test if a name is on the table? Its eazy, you must use a For Loop!
Example:
TestTable = {"Leamir", "Is A Noob"} for i,v in pairs(TestTable) do print(v) -- This will print "Leamir" and the "Is A Noob" if v == "Leamir" then -- This will test if table has "Leamir", you can use a player name! OnTable = true end if OnTable = true then print(v .. " is on the table!") OnTable = false else print(v .. "isn't on the table") end end
I also made a script to test if a random player is on the table, if not add it!
local Players = game.Players:GetChildren() local Table = {} for i,v in pairs(Table) do if v == Players[math.Random(1, #Players)] then -- This will test if table has a random player name! OnTable = true end if OnTable = true then print(v .. " is on the table!") OnTable = false else print(v .. "isn't on the table") table.Insert(Table, v) end end
Helpful articles:
Good Luck with your games!