|
| 17 Nov 2016 03:49 AM |
hi, i have this script that should clone everything in a table, but when i run it it does clone everything, but it also errors. the error is:
Workspace.Regeneration:18: attempt to index local 'p' (a nil value)
the script is:
local regen = {}
for i,v in pairs(game.Workspace:GetChildren()) do --put stuff in backup if v.ClassName ~= "Terrain" and v.ClassName ~= "Camera" then table.insert(regen,v) end end
wait(3)
parts = 1
for i=1,#regen do --backup everything local p = regen[parts]:clone() if p.Name ~= "Regeneration" then p.Parent = workspace end parts = parts+1 end
regen = {} --empty backup table
what did i do wrong? |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Nov 2016 08:20 AM |
like i said
local p = regen[i]:Clone() *
|
|
|
| Report Abuse |
|
|
|
| 17 Nov 2016 08:38 AM |
it errored this:
Workspace.Regeneration:16: attempt to index local 'p' (a nil value)
line 16 is the one you just wrote. |
|
|
| Report Abuse |
|
|
| |
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
| |
|
|
| 18 Nov 2016 07:01 AM |
local regen = {}
for _,v in pairs(workspace:GetChildren()) do if not (v:IsA("Camera") or v:IsA("Terrain")) and v.Name ~= "Regeneration" then table.insert(regen,v:Clone()) end end
wait(3)
for i = #regen,1,-1 do local obj = regen[i] table.remove(regen,i) obj.Parent = workspace end
|
|
|
| Report Abuse |
|
|
|
| 18 Nov 2016 08:11 AM |
| clonetrooper, thank you so much! |
|
|
| Report Abuse |
|
|