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

How do I clone all values in table?

Hello, I want to clone my item table into the workspace but I always get this: attempt to call method 'Clone' (a nil value), but It should have a value

Script:

local serverstorage = game:GetService("ServerStorage")
local items = {serverstorage.Folder.food, serverstorage.Folder.food1, serverstorage.Folder.food2}

for i, v in pairs(items) do
	local item = (items):Clone()
	item.Parent = workspace
	end

Thank you.

2 answers

✓ Accepted answer

It would be easier to start with an empty table and insert the names of the items first and then clone them and put them into workspace.

ServerScript inside of ServerScriptService

--// Empty Table
local items = {}

--// Where You Want Them To Load Into [CHANGEABLE]
local loadPlace = game:GetService("Workspace")

--// Folder You Want To Load Into The Table [CHANGEABLE]
local folder = game:GetService("ServerStorage"):WaitForChild("Folder") --// Change Folder To The Name Of YOUR Folder

--// Waits For Game To Set [CHANGEABLE]
wait(2.5)

--// Inserts All Items From ServerStorage Folder Into Table
for _,item in pairs(folder:GetChildren()) do
	table.insert(items,item.Name)
	wait()
end

--// Waits For The Table To Settle In [CHANGEABLE]
wait(1)

--// Finds All The Items In The Folder With The Name Of The Current Item, Clones It, And Puts It Into The LoadPlace Variable
for _,item in pairs(items) do
	local newItem = folder:FindFirstChild(item):Clone()
	newItem.Parent = game:GetService(loadPlace)
	print("Loaded "..item.." Into "..loadPlace) --// This Line Is For Testing Purposes [CHANGEABLE]
	wait()
end
  1. Created an empty table to store all the values
  1. Set all easy changeable variables
  1. Inserted all the names of the items inside the folders in ServerStorage into the table
  1. Looked for the name of the item in the folder in ServerStorage and cloned it into workspace

Hope this helped! If it didn't work, let me know by commenting down below what error occurs. If it does work, let me know by taking this as the answer!

~killerbrenden

6 comments

0

But it all depends on how you do it and what you want to do with it.

0

Thank you.

0

No problem!

0

Well I dont get any errors but it doesn't clone them :(

0

Nvm, the problem is at line 25, instead of game:GetService(loadPlace) just type loadPlace

0

Glad to help.

items is the table, what you actually want is to clone v as that is the Instance

Wiki

Iterating Over Arrays

Don't forget to mark my answer as the solution if it solved your problem :)

2 comments

0

thx m8

0

np

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