local TeleportService = game:GetService("TeleportService")
local dVersion = 1
local VIPGamepass = 0
local WinsDataStore = game:GetService("DataStoreService"):GetDataStore('Wins')
game.Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new('Folder')
Stats.Name = 'leaderstats'
Stats.Parent = Player
local Wins = Instance.new('IntValue')
Wins.Name = 'Wins'
Wins.Parent = Stats
local Data = WinsDataStore:GetAsync(Player.UserId)
if Data then
for name, value in pairs(Data.Stats) do
Stats[name].Value = value
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local SaveData = {Stats = {}}
for _, stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local SaveData = {Stats = {}}
for _,stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
end
wait(2)
end)
local SaveCoins = game:GetService("DataStoreService"):GetOrderedDataStore("Coins", dVersion)
game.Players.PlayerAdded:Connect(function(player)
local previousData = SaveCoins:GetAsync(player.UserId)
local Coins
if previousData ~= nil then
Coins = previousData
else
Coins = 0
SaveCoins:SetAsync(player.UserId, 0)
end
local WinsValue = Instance.new("NumberValue", player)
WinsValue.Name = "Coins"
WinsValue.Value = Coins
local val1 = Instance.new("StringValue",player)
val1.Name = 'GotPet'
val1.Value = ''
local val2 = Instance.new("StringValue",player)
val2.Name = 'OpenValue'
val2.Value = ''
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
player.Coins.Value = player.Coins.Value *2
end
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
local Value = player.Coins.Value
SaveCoins:SetAsync(player.UserId, Value)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Value = player.Coins.Value
if Value ~= nil then
print("Found data to save for "..player.Name.."!")
SaveCoins:SetAsync(player.UserId, Value)
print("Saved data for "..player.Name)
else
print("Did not manage to find data to save for "..player.Name.."!")
end
end)
local DonatedDataStore = game:GetService("DataStoreService"):GetDataStore('Donated')
game.Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new('Folder')
Stats.Name = 'leaderstats'
Stats.Parent = Player
local Donated = Instance.new('IntValue')
Donated.Name = 'Donated'
Donated.Parent = Stats
local Data = DonatedDataStore:GetAsync(Player.UserId)
if Data then
for name, value in pairs(Data.Stats) do
Stats[name].Value = value
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local SaveData = {Stats = {}}
for _, stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
DonatedDataStore:SetAsync(Player.UserId,SaveData)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local SaveData = {Stats = {}}
for _,stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
DonatedDataStore:SetAsync(Player.UserId,SaveData)
end
wait(2)
end)
local TeleportData = TeleportService:GetLocalPlayerTeleportData()
if TeleportData then
local player = game.Players:GetPlayerByUserId(TeleportData.PlayerName)
player:WaitForChild("leaderstats"):WaitForChild("Wins").Value = player.leaderstats.Wins.Value + 1
end