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

Adding to tables with script?

Asked by 8 years ago

So I am creating a script that should save the children of an object's names and cframes in the same order, in two tables, kind of like a table with a key. I would be able to save object sand their cframes in that way. What i need to do now is add things to a different table and in the same order as the first table. I think that the script below may work but i still cannot find how i would make and add things to a table with script.

Script

    while true do
        wait(60)
        local pur=script.Parent.Parent.Parent.Purchased
        local pnumb=#pur:GetChildren()
        local table={}
        local purs=pur:GetChildren()
        PlayerData:SetAsync(("objects".. plyr.UserId),{purs})
        for i=1, pnumb do
            local puri = table.remove(purs,i)
                     --Here is where i would like it to add puri to a new table called table
                end
        end
        PlayerData:SetAsync(("cframes".. plyr.UserId),{table})
    end

1 answer

Log in to vote
0
Answered by 8 years ago

Yo would just use the table.insert method, which should work with the rest of the script unless there are any other errors before that. Also in line 11 you had a random unnecessary end.

while true do
    wait(60)
    local pur=script.Parent.Parent.Parent.Purchased
    local pnumb=#pur:GetChildren()
    local table={}
    local purs=pur:GetChildren()
    PlayerData:SetAsync(("objects".. plyr.UserId),{purs})
    for i=1, pnumb do
        local puri = table.remove(purs,i)
                 --Here is where i would like it to add puri to a new table called table
        table.insert(table, puri)
    end
    PlayerData:SetAsync(("cframes".. plyr.UserId),{table})
end



Ad

Answer this question