I would like that the script will insert the items in the table as they are the main things in the game and it looks like there is data loss, but the items are never saved in the table so neither in the DataStore.
I tried to put certain prints where I thought there was the problem, but I can't figure it out. I printed everything that was in the table at the moment of purchasing and it seems that there is a problem at the insertion.
I put an else to see if the problem might rely on that if statement, but there was no print on the else.
Stuff that you should know:
- the function "Purchase" is called everytime the player buys a new tycoon item
- "Tycoon" is a model that contains the whole tycoon (items, buttons, decorations etc)
- "Owner" memorizes the player instance that owns the tycoon
- "item" is the button on which the player stepped to buy
- "Objects" is the stuff bought
Any ideas?
If you need more details, please ask.
function Purchase(tbl)
local userTycoon = DataStore2("Tycoon",script.Parent.Owner.Value):Get({})
local cost = tbl[1]
local item = tbl[2]
local stats = tbl[3]
if not script.Parent.PurchasedObjects:FindFirstChild(item.Object.Value) then
stats.Value = stats.Value - cost
end
Objects[item.Object.Value].Parent = script.Parent.PurchasedObjects
if(table.find(userTycoon, item.Object.Value) == nil ) then
table.insert(userTycoon,item.Object.Value)
local wow = item.Object.Value
for index, wow in pairs(userTycoon) do
print(wow)
end
DataStore2("Tycoon",script.Parent.Owner.Value):Set(userTycoon)
local zep = script.Parent.Owner.Value
DataStore2("Cash",script.Parent.Owner.Value):Set(game.ServerStorage:WaitForChild("PlayerMoney"):WaitForChild(zep.Name).Value)
else
print("No insertion has been made cause I don't want to")
end

2 comments
DataStore2("Tycoon",script.Parent.Owner.Value):Get({}) --- Is this a real function?
Yes, from the "DataStore2 module". It gets the table in the datastore. with "Set" function you say what table to save.