Hello developers, im currently trying to make a datasave script save a model with all the items the players has purchased in the game but im not really sure on how to. I tried doing data.purchasedmodels = game.Workspace.PurchasedItems but it didnt work. If anyone could help me out, it would be very appreciated!
datasave script:
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("DataStore")
MPS = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = folder
local data
local success,errorMsg = pcall(function()
data = datastore:GetAsync(player.UserId)
end)
if data ~= nil then
if data.Cash then
cash.Value = data.Cash
end
end
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
local data = {}
data.Cash = player.leaderstats.Cash.Value
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {}
data.Cash = player.leaderstats.Cash.Value
local success,errorMsg = pcall(function()
datastore:SetAsync(player.UserId,data)
end)
if success then
print("Success")
end
if errorMsg then
print("Error found while trying to save data (are roblox datastore servers down?)"..errorMsg)
end
end)
end)