Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you save model positions?

Line 20 is erroring with:

Players.Player1.PlayerGui.Save_Data.Frame.Save.Saving:20: bad argument #1 to 'insert' (table expected, got nil)

here is the code:

local player = script.Parent.Parent.Parent.Parent
local ItemStore = game:GetService("DataStoreService"):GetDataStore("itemstore")
local objects = ItemStore:GetAsync("Details" .. player.Name)
if objects ~= nil then
for i = #objects, 1, -1 do
    print(objects[1])   
    Item = game.ServerStorage.Items[objects[i-3]]:Clone()
    Item.PrimaryPart = Item.Hitbox
    coord1 = objects[i-2]
    coord2 = objects[i-1]
    coord3 = objects[i]
    Item:SetPrimaryPartCFrame(CFrame.new(coord1,coord2,coord2))
    Item.Parent = game.Workspace
    end
end

script.Parent.MouseButton1Click:connect(function()
    local findItems = workspace.Placed:GetChildren()
    for i = #findItems, 1, -1 do
    table.insert(objects,i-3,findItems[i].Name)
    table.insert(objects,i-2,tostring(findItems[i].Hitbox.Position.X))
    table.insert(objects,i-1,tostring(findItems[i].Hitbox.Position.Y))
    table.insert(objects,i,tostring(findItems[i].Hitbox.Position.Z))
	print(objects[i-3].." "..objects[i-2].." "..objects[i-1].." "..objects[i])  
    end
    ItemStore:SetAsync("Details" .. player.Name, objects)
end)

1 answer

✓ Accepted answer

It's telling you that the objects table is nil, because the player has no saved info. This is inevitable. Simple fix:

local objects = ItemStore:GetAsync("Details" .. player.Name) or {}

This discussion is preserved as it was. New answers, comments, and votes are closed.