local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local ItemsFolder = Instance.new("Folder")
ItemsFolder.Name = "ItemsFolder"
ItemsFolder.Parent = player
local PlayerId = "Player_" .. player.UserId
local data = nil
local success, errormessage = pcall(function()
data = MyDataStore:GetAsync(PlayerId)
end)
if data then
local NewPet = data:Clone()
NewPet.Parent = ItemsFolder
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local PlayerId = "Player_" .. player.UserId
if player.ItemsFolder:FindFirstChildWhichIsA("Folder") then
local data = player.ItemsFolder.PetOne
local success, errormessage = pcall(function()
MyDataStore:SetAsync(PlayerId, data)
end)
if success then
print("Success")
elseif errormessage then
warn(errormessage)
end
end
end)
game:BindToClose(function()
wait(1)
end)
So I’ve been looking on YouTube for a video on how to save instances in a DataStore. In my case, the instance would be a pet or item in someone’s backpack which stores information about their pet/item. Unfortunately, I couldn’t find a good video or a clear/common answer from devforum posts either. Is there a simple way to do this?