Also how would I do that?I tried some things out but they didn't worked my script:

local PetsDS = game:GetService("DataStoreService"):GetDataStore("PetSave")

game.Players.PlayerAdded:Connect(function(Player)

local PetsFolder = Instance.new("Folder")

PetsFolder.Name = "Pets"

PetsFolder.Parent = Player

local key = Player.UserId

pcall(function()

local Pets = PetsDS:GetAsync(key)

if Pets then

for i,v in pairs (Pets) do

local Pet = Instance.new("IntValue")

Pet.Parent = PetsFolder

if Pet then

Pet.Name = v.Name

end

end

end

end)

end)

game.Players.PlayerRemoving:Connect(function(Player)

local key = Player.UserId

pcall(function()

local PetsToSave = {}

for i,v in pairs(Player.Pets:GetChildren()) do

if v then

table.insert(PetsToSave,v.Name)

end

end

PetsDS:SetAsync(key,PetsToSave)

end)

end)

How can I improve it that I can save too the value of it?

1 comment

0

Wrap your code in a lua code block