So i have 2 parts in a model named Part1 and Part2. I inserted part1 into a table, so how can i use that part from the table on other things.
db = false touch = script.Parent model = touch.Parent allparts = model:GetChildren() tab = {} touch.Touched:Connect(function() if db == false then db = true for i,v in pairs(allparts)do if v.name == "Part1" then table.insert(tab,model.Part1) for i = 1,20 do tab[1].CFrame = tab[1].CFrame * Vector3.new(0,0.05,0) --Error wait() end print(tab[1]) end end db = false end end)
it's saying tab[1] won't work in line 14, even though in my mind it's litterly the same thing as Part1, so i just want to take out "Part1" in the table and make it into a variable.
Look i wasn't sure if this is what you wanted but it seems as though it was what you were trying to do.
local db = false -- MAKE ALL THESE LOCAL VARIABLES (it's faster) local touch = script.Parent local model = touch.Parent local allparts = model:GetChildren() local tab = {} touch.Touched:Connect(function() if db == false then db = true for i,v in pairs(allparts)do if v.name == "Part1" then table.insert(tab,v) -- model.Part1 is the same as v print(tab[v]) end end for i = 1,#tab do -- #tab is the amount of values in the array, "tab" tab[i].CFrame = tab[i].CFrame * Vector3.new(0,0.05,0) wait() end db = false end end)