local Players = game:GetService('Players')
local TeleportService = game:GetService("TeleportService")
local dVersion = 1
local WinsDataStore = game:GetService("DataStoreService"):GetDataStore("Wins")
local RoundsDataStore = game:GetService("DataStoreService"):GetDataStore("Rounds")
local VIP = 81050904
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 Rounds = Instance.new("IntValue")
Rounds.Name = "Rounds"
Rounds.Parent = Stats
local Data = WinsDataStore:GetAsync(Player.UserId)
local Data2 = RoundsDataStore:GetAsync(Player.UserId)
if Data then
for name, value in pairs(Data.Stats) do
Stats[name].Value = value
end
end
if Data2 then
for name, value in pairs(Data2.Stats) do
Stats[name].Value = value
end
end
end)
Players.PlayerRemoving:Connect(function(Player)
local SaveData = {Stats = {}}
local SaveData2 = {Stats = {}}
for _, stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
for _, stat2 in pairs(Player.leaderstats:GetChildren()) do
SaveData2.Stats[stat2.Name] = stat2.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
RoundsDataStore:SetAsync(Player.UserId,SaveData2)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local SaveData = {Stats = {}}
local SaveData2 = {Stats = {}}
for _,stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
for _,stat2 in pairs(Player.leaderstats:GetChildren()) do
SaveData2.Stats[stat2.Name] = stat2.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
RoundsDataStore:SetAsync(Player.UserId,SaveData2)
end
wait(2)
end)
local CoinsSave = game:GetService("DataStoreService"):GetOrderedDataStore("Coins "..dVersion)
game.Players.PlayerAdded:Connect(function(player)
local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
local Coins
if previousData ~= nil then
Coins = previousData
else
Coins = 0
CoinsSave:SetAsync(player.UserId, 0)
end
local coinsValue = Instance.new("IntValue", player)
coinsValue.Name = "Coins"
coinsValue.Value = Coins
local val1 = Instance.new("StringValue",player)
val1.Name = 'GotPet'
val1.Value = ''
local val2 = Instance.new("StringValue",player)
val2.Name = 'OpenValue'
val2.Value = ''
end)
game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
print("STOPPED!")
for i,player in pairs(game.Players:GetPlayers()) do
local value = player.Coins.Value
CoinsSave:SetAsync(player.UserId, value)
print("Saved data for "..player.Name)
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.."!")
CoinsSave: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 SaveExtraLives = game:GetService("DataStoreService"):GetOrderedDataStore("Lives "..dVersion)
game.Players.PlayerAdded:Connect(function(player)
local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
local Lives
if previousData ~= nil then
Lives = previousData
else
Lives = 0
CoinsSave:SetAsync(player.UserId, 0)
end
local coinsValue = Instance.new("IntValue", player)
coinsValue.Name = "Lives"
coinsValue.Value = Lives
end)
game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
print("STOPPED!")
for i,player in pairs(game.Players:GetPlayers()) do
local value = player.Lives.Value
SaveExtraLives:SetAsync(player.UserId, value)
print("Saved data for "..player.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local value = player.Lives.Value
if value ~= nil then
print("Found data to save for "..player.Name.."!")
SaveExtraLives: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)
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
RoundsDataStore:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
SaveExtraLives:SetAsync(player.UserId, player.Lives.Value)
player.Lives.Value = player.Lives.Value - 1
player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
end)
end)
end)