I want to make a sort of virtual pet game, and specifically sava data of the dog you have. The problem is I want multiple dogs to be saved, but if I continue to do it this way it’ll be inefficient.
I’ve considered Table datastores but I’m not good at datastores in the first place, so I would need help for it. I would rather not use a datastore module thats not roblox, because last time I used a datastore module it stopped updating, and I had to recode the datastore.
I want an efficent way to save data for multiple dogs, ideally in a way where I don’t have to make a separate datastore for each dog.
local players = game:GetService("Players")
DataStoreService = game:GetService("DataStoreService")
local Runservice = game:GetService("RunService")
local Dog1DataStore = DataStoreService:GetDataStore("CashDataStore")
players.PlayerAdded:Connect(function(plr)
local DogsFolder = Instance.new("Folder")
DogsFolder.Name = "dogs"
DogsFolder.Parent = plr
-- dog 1
local Dog1 = Instance.new("Folder")
Dog1.Name = "Dog1"
Dog1.Parent = DogsFolder
local buyed = Instance.new("BoolValue")
buyed.Name = "DogBuyed"
buyed.Value = false
buyed.Parent = Dog1
local name = Instance.new("StringValue")
name.Name = "DogName"
name.Value = nil
name.Parent = Dog1
local skin = Instance.new("StringValue")
skin.Name = "DogSkin"
skin.Value = nil
skin.Parent = Dog1
wait(1)
local dogdata = Dog1DataStore:GetAsync(plr.UserId)
if dogdata then
if buyed.Value == false then
buyed.Value = true
name.Value = "Hal"
skin.Value = "White"
end
else
print("No data")
Dog1DataStore:SetAsync(plr.UserId, true)
end
end)
players.PlayerRemoving:Connect(function(plr)
if not Runservice:IsStudio() then
game:BindToClose(function()
if game.Players:GetPlayers() <= 1 then return end
local PlayerDog1 = plr.leaderstats:WaitForChild("Dog1")
Dog1DataStore:SetAsync(plr.UserId, PlayerDog1.Value)
end)
end
end)