#How do I save items that players have bought from my shop into datastores?

5 messages · Page 1 of 1 (latest)

eternal perch
#

for example by saving a dictionary that uses the item names as keys and values as flags for ownership

flat coyote
#

u basically answered ur own question

eternal perch
graceful terrace
#

local DataSToreService = game:GetService("DataStoreService")
local DataStore = DataSToreService:GetDataStore("myDataStore")
local key = 0 -- Changing this number practiavlly gives you a new datastore. You can always load old saves by taking an old key value

game.Players.PlayerAdded:Connect(function(player) -- When a player joines we want to load the data

local cafeName = Instance.new("StringValue")
cafeName.Name = "CafeName"
cafeName.Parent = player
cafeName.Value = "No name"


local savedNameData = nil
pcall(function()
    savedNameData = DataStore:GetAsync("CafeName_"..player.UserId..key) -- Here we load the data
end)

if savedNameData then -- if we successfully loaded the data we set the player.Money.Value to the loaded value
    player.CafeName.Value = savedNameData
    print("Seccussful cafe name load")
else
    player.CafeName.Value = "No Name - Error loading"
    print("Error loading cafe name")
end

end)

#

game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves we want to save the data

pcall(function()
    DataStore:SetAsync("CafeName_"..player.UserId..key, player.Money.Value) 
end)    

end)