Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TeleportService = game:GetService("TeleportService")
- local DataStoreService = game:GetService("DataStoreService")
- local PetStore = DataStoreService:GetDataStore("PetData")
- local numberValue = 0
- game.Players.PlayerAdded:Connect(function(Player)
- local Coins = Instance.new("NumberValue")
- Coins.Name = "Coins"
- Coins.Parent = Player
- local OwnedPets = Instance.new("Folder")
- OwnedPets.Name = "OwnedPets"
- OwnedPets.Parent = Player
- local EquippedPet = Instance.new("StringValue")
- EquippedPet.Name = "EquippedPet"
- EquippedPet.Parent = Player
- local Success, Data = pcall(function()
- return PetStore:GetAsync(Player.UserId)
- end)
- if Success and Data then
- Coins.Value = Data.Coins or numberValue
- EquippedPet.Value = Data.EquippedPet or ""
- if Data.OwnedPets then
- for PetName, HasPet in pairs(Data.OwnedPets) do
- if HasPet then
- local Pet = Instance.new("BoolValue")
- Pet.Name = PetName
- Pet.Parent = OwnedPets
- end
- end
- end
- else
- Coins.Value = numberValue
- end
- end)
- game.Players.PlayerRemoving:Connect(function(Player)
- local Pets = {}
- for _, Pet in ipairs(Player.OwnedPets:GetChildren()) do
- Pets[Pet.Name] = true
- end
- pcall(function()
- PetStore:SetAsync(Player.UserId,{
- Coins = Player.Coins.Value,
- OwnedPets = Pets,
- EquippedPet = Player.EquippedPet.Value
- })
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment