Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

table.insert with multiple lines?

In a part of a script I have:

_G.Army = {}
_G.Army[1] = {
	Morale = 100,
	MP = 100
}

In another LocalScript I have:

local LocalPlayer = game.Players.LocalPlayer
local Tool = LocalPlayer.Backpack.Tool

Tool.Activated:connect(function()
	local NewArmy = table.insert(_G.Army, #_G.Army + 1, "Placeholder")
end)

The problem I am experiencing is, how do I add multiple lines for the value of the element when I run table.insert? So instead of putting just "Placeholder" for the next _G.Army[2], I can use the template:

Morale = 0,
MP = 0

2 comments

0

tbl['NAME'] = VALUE?

0

local NewArmy = table.insert(_G.Army, #_G.Army + 1, {Morale = 0, MP = 0})

1 answer

Simply put a table where "PlaceHolder" is.

local LocalPlayer = game.Players.LocalPlayer
local Tool = script.Parent --just put this inside the tool bruh
local placeHolder = {Morale=0;MP=0}

--'connect' is deprecated.
Tool.Activated:Connect(function()
	local NewArmy = table.insert(_G.Army, #_G.Army + 1, placeHolder)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.