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

How Do I Make A "Table" That Stores Objects?

Here's what I mean:

ObjectStorage = {}
function getObjects()
	for i,v in pairs(workspace.Objects:GetChildren()) do
		if v:IsA('Part') then
			return v
		end
	end
	return nil
end
function getStoredObjects()
	for i,v in pairs(workspace.ObjectNames:GetChildren()) do
		if v:IsA('StringValue') then
			return v
		end
	end
	return nil
end
workspace.Store.Touched:Connect(function()
	local object = getObjects()
	ObjectStorage[object.Name] = object:clone()
	object:destroy()
end)
workspace.Grab.Touched:Connect(function()
	local object = getStoredObjects()
	ObjectStorage[object.Name].Parent = workspace.Objects
end)

If that works then please comment 'it works'.

1 answer

It doesn't work cause it doesn't add anything to the table if you want to add something to the table called: "ObjectStorage" call the function

table.insert(table name, item to add)

table.insert(ObjectStorage, "example")

to get the list of it do

for i,v in pairs(ObjectStorage) do
	print(v)
end

Source: developer.roblox.com/api-reference/lua-docs/table

2 comments

0

tbl[#tbl+1] = x <-- this method is faster than using table.Insert

0

But table.insert is easier.

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