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

How do I clone all values in table?

Asked by
JoneXI 51
4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

2) Set all easy changeable variables

3) Inserted all the names of the items inside the folders in ServerStorage into the table

4) 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

0
But it all depends on how you do it and what you want to do with it. killerbrenden 1537 — 4y
0
Thank you. JoneXI 51 — 4y
0
No problem! killerbrenden 1537 — 4y
0
Well I dont get any errors but it doesn't clone them :( JoneXI 51 — 4y
View all comments (2 more)
0
Nvm, the problem is at line 25, instead of game:GetService(loadPlace) just type loadPlace JoneXI 51 — 4y
0
Glad to help. killerbrenden 1537 — 4y
Ad
Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

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 :)

0
thx m8 JoneXI 51 — 4y
0
np Filipalla 504 — 4y

Answer this question