So i'm trying to save my table of objects and their locations to a datastore, but when I go to read the table. The only item in there is the first X coord of an item. I'm quite sure it's only saving one number then stopping. I'm not sure what's wrong though.
-- Saving Part --
local ItemStore = game:GetService("DataStoreService"):GetDataStore("itemstore")
script.Parent.MouseButton1Click:connect(function()
player = script.Parent.Parent.Parent.Parent
findItems = game.Workspace.Tycoons.GoldMine1.Objects:GetChildren()
for i = #findItems, 1, -1 do
objects = {}
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)
Saving seems to work as when I print out the table I get this
Dual Dropper -38.5 5 60
Dual Dropper -44.5 5 54
BB -62.5 -0.5 99
-- Loading Part --
local objects = ItemStore:GetAsync("Details" .. player.Name)
if objects ~= nil then
for i = #objects, 1, -1 do
print(objects[1])
Item = game.ReplicatedStorage.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
I'm getting this error when loading
Workspace.onPlayerAdded:5: bad argument #2 to '?' (string expected, got nil)

4 comments
Its nice that you give us an error, but it doesnt link to the script that you put in as it isnt the full script.
There's no need to give the full script. The error is referring to line 5 on the loading part of the script above.
Please tell me if my answer fixed your problem or not. If not, is it still gives same error output? Or is your question closed?
I managed to fix it. The table was being wiped clean at the start of every loop. I didn't realise I left objects={} in there.