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

How do i take a part out of a table to use it?

Asked by 6 years ago

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.

0
Any Errors? If so tell me the error MrGaming4me 28 — 6y
0
The error is that in line 14 tab[1] is equal to saying Part1, but it's not working. so the part isn't moving. nikki9dor 28 — 6y
0
Dude why do you have a for loop and you aren't even using it. Like "i = 1,20" but in the actual loop i cannot see an "i" Aznarog 54 — 6y
0
The loop is for the CFrame inside the loop, guy. nikki9dor 28 — 6y

1 answer

Log in to vote
0
Answered by
Aznarog 54
6 years ago
Edited 6 years ago

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)
0
I tried some of the stuff you showed me, and went back to mines. Turns out that a part from a table cannot be used with CFrame, at least with what i've seen, it's not working at all with CFrame but it works with like change the color or doing anything with the part. nikki9dor 28 — 6y
0
Nvm, i found the error. Just switch a couple of lines up and i got when i wanted. I'll accept you're answer for helping out, but it was not what i was looking for. No harsh feelings. Thanks for putting effort on helping :) nikki9dor 28 — 6y
0
ight glad i could help man Aznarog 54 — 6y
Ad

Answer this question