I get this error : Cannot convert mixed or non-array tables: keys must be strings on this line
datastore:SetAsync(player.UserId,data2)
Yet I have similar scripts that save similar tables which work. Any ideas? Whole code:
function save(player,data)
local data2={
["Bed"]=0,
["Chest"]=0,
["Fireplace"]=0,
["Foundations"]=0,
["Furniture"]=0,
["Walls&Roof"]=0,
["Wooden Structure"]=0
}
for i,v in pairs(data) do
data2[v] = 1
end
local datastore = game:GetService("DataStoreService"):GetDataStore("Housing")
datastore:SetAsync(player.UserId,data2)
end
--PLAYER LEAVES---------------
game.Players.PlayerRemoving:connect(function(player)
local data= player.HasTycoon.houseBuilds:GetChildren()
if data then
save(player,data)
end
end)
EDIT: as suggested this line
datastore:SetAsync(player.UserId,data2)
was updated to
datastore:SetAsync(tostring(player.UserId),data2)
but the problem persists with the same error message

11 comments
The key has to be a string, so try doing: key="user_"..player.UserId
I dont get it, would you explain a bit more?
UserId is a int and not a string, you could use tostring() to convert it.
Oh, I did but I still get the same error
Can you also update the code above.
Updated
What does houseBuilds hold?
houseBuilds is a folder that contains BoolValues named after the parts builts
The problem is that a data store cannot save an object you will need to go into each of these folders and get the value and put it into your table.
This solved the problem many thanks!
Can you add to the title [answered] or [closed] it just helps other ppl