Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you add an additional value into your table?

Asked by 5 years ago
Edited 5 years ago

I want to know how I would be able to place a value and create a new spot on a table. --Example local currenttable = {userid,userid} --How to add values here. --lets say if I made a ban command game.Players.PlayerAdded:Connect(function(player) if player ~= nil then player.Chatted:Connect(function(msg) if string.lower(string.sub(msg, 1, 4) == "!ban" then local target = game.Players:FindFirstChild(string.sub(string.sub(msg 6, ) local userId = target.UserId table.insert() --This is the part I need help with...

--Me don't know how many ends.
........ I don't know what to do after that point. legit wrote this script on the website please don't mind the deprecated or spelled wrong text.....

1 answer

Log in to vote
1
Answered by 5 years ago

To add values to a table you use table.insert with 3 parameters, the table you want to insert a value into, the position in the table you want your value to go to, and the value you want to insert into the table. Here's some examples:

local myTable = {1, 3, 4}
table.insert(myTable, 2, 2)

myTable now equals {1, 2, 3, 4}

local myTable = {1, 2, 3}
table.insert(myTable, #myTable + 1, 4) -- #myTable + 1 adds the value to the end of the table

myTable now equals {1, 2, 3, 4} Hope this helps!

Ad

Answer this question