You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
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.
- What is the issue? Include screenshots / videos if possible!
Items are not inserted as desired.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
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
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.