Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dss = game:GetService("DataStoreService")
- local ds = dss:GetDataStore("datastore")
- function saveData(plr)
- local cash = plr.leaderstats.Cash.Value
- local ownedPets = {}
- for i, pet in pairs(plr.OwnedPets:GetChildren()) do
- table.insert(ownedPets, pet.Name)
- end
- ds:SetAsync(plr.UserId .. "PETS", ownedPets)
- ds:SetAsync(plr.UserId .. "CASH", cash)
- end
- game.Players.PlayerAdded:Connect(function(plr)
- plr.CharacterAdded:Connect(function(char)
- char.ChildAdded:Connect(function(child)
- if child.Name == "EquippedPet" then
- local bp = Instance.new("BodyPosition", child)
- local bg = Instance.new("BodyGyro", child)
- bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
- local hrp = char.HumanoidRootPart
- while child.Parent == char do
- wait()
- bp.Position = hrp.Position - (hrp.CFrame.RightVector * 5)
- bg.CFrame = CFrame.new(hrp.Position, hrp.CFrame.LookVector * 10000)
- end
- end
- end)
- end)
- local ls = Instance.new("Folder", plr)
- ls.Name = "leaderstats"
- local cash = Instance.new("IntValue", ls)
- cash.Name = "Cash"
- local ownedPets = Instance.new("Folder", plr)
- ownedPets.Name = "OwnedPets"
- pcall(function()
- local petsData = ds:GetAsync(plr.UserId .. "PETS")
- local cashData = ds:GetAsync(plr.UserId .. "CASH")
- cash.Value = cashData or 10000
- for i, petName in pairs(petsData) do
- for x, descendant in pairs(game.ReplicatedStorage:WaitForChild("Pets"):GetDescendants()) do
- if descendant.Name == petName then
- descendant:Clone().Parent = ownedPets
- end
- end
- end
- end)
- end)
- game.Players.PlayerRemoving:Connect(saveData)
- game:BindToClose(function()
- for i, plr in pairs(game.Players:GetPlayers()) do
- saveData(plr)
- end
- end)
- for i, descendant in pairs(workspace:GetDescendants()) do
- if descendant:FindFirstChild("Properties") then
- local price = descendant.Properties.Price.Value
- descendant.BuyButton.BuyGui.BuyTextLabel.Text = "Buy for " .. price
- local rarities = {}
- for x, rarity in pairs(descendant.Properties.Rarities:GetChildren()) do
- rarities[rarity.Name] = rarity.Value
- end
- local pets = {}
- for x, rarityFolder in pairs(game.ReplicatedStorage.Pets[descendant.Name]:GetChildren()) do
- local percent = rarities[rarityFolder.Name]
- for y, pet in pairs(rarityFolder:GetChildren()) do
- for z = 1, percent do
- table.insert(pets, pet)
- end
- end
- end
- descendant.BuyButton.ClickDetector.MouseClick:Connect(function(plr)
- if plr.leaderstats.Cash.Value >= price then
- plr.leaderstats.Cash.Value -= price
- local randomPet = pets[math.random(1, #pets)]
- game.ReplicatedStorage.PetSystemRE:FireClient(plr, randomPet)
- randomPet:Clone().Parent = plr.OwnedPets
- end
- end)
- end
- end
- game.ReplicatedStorage.PetSystemRE.OnServerEvent:Connect(function(plr, petToEquip)
- if plr.Character and petToEquip.Parent == plr.OwnedPets then
- local createNewPet = true
- if plr.Character:FindFirstChild("EquippedPet") then
- if plr.Character.EquippedPet.Decal.Texture == petToEquip.Decal.Texture and plr.Character.EquippedPet.Color == petToEquip.Color then
- createNewPet = false
- end
- plr.Character.EquippedPet:Destroy()
- end
- if createNewPet then
- local newPet = petToEquip:Clone()
- newPet.Name = "EquippedPet"
- newPet.CFrame = plr.Character.HumanoidRootPart.CFrame
- newPet.Parent = plr.Character
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement