CCCPaste

New Wins and Rounds with VIP(Main Game)

local TeleportService = game:GetService("TeleportService")
local dVersion = 1
local save = game:GetService("DataStoreService"):GetOrderedDataStore("Wins "..dVersion)
local MPS = game:GetService("MarketplaceService")
local VIPGamepassId = 48592364

game.Players.PlayerAdded:Connect(function(player)
local previousData = save:GetAsync(player.UserId) -- Returns a number value.

local Wins

if previousData ~= nil then
Wins = previousData
else
Wins = 0
save:SetAsync(player.UserId, 0)
end

local coinsValue = Instance.new("IntValue", player)
coinsValue.Name = "Wins"
coinsValue.Value = Wins
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.Wins.Value
save:SetAsync(player.UserId, value)
print("Saved data for "..player.Name)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local value = player.Wins.Value

if value ~= nil then
print("Found data to save for "..player.Name.."!")
save: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 save2 = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds "..dVersion)

game.Players.PlayerAdded:Connect(function(player)
local previousData = save2:GetAsync(player.UserId) -- Returns a number value.

local Rounds

if previousData ~= nil then
Rounds = previousData
else
Rounds = 0
save2:SetAsync(player.UserId, 0)
end

local coinsValue = Instance.new("IntValue", player)
coinsValue.Name = "Rounds"
coinsValue.Value = Rounds
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.Rounds.Value
save2:SetAsync(player.UserId, value)
print("Saved data for "..player.Name)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local value = player.Rounds.Value

if value ~= nil then
print("Found data to save for "..player.Name.."!")
save2: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 save3 = game:GetService("DataStoreService"):GetOrderedDataStore("Level "..dVersion)
local save4 = game:GetService("DataStoreService"):GetOrderedDataStore("Exp "..dVersion)
local save5 = game:GetService("DataStoreService"):GetOrderedDataStore("RequiredExp "..dVersion)
game.Players.PlayerAdded:Connect(function(player)
local previousData = save2:GetAsync(player.UserId) -- Returns a number value.
local previousData2 = save4:GetAsync(player.UserId)
local previousData3 = save5:GetAsync(player.UserId)

local Level
local Exp
local RequiredExp

if previousData ~= nil then
Level = previousData
else
Level = 0
save3:SetAsync(player.UserId, 0)
end

if previousData2 ~= nil then
Exp = previousData2
else
Exp = 0
save4:SetAsync(player.UserId, 0)
end

if previousData3 ~= nil then
RequiredExp = Level * 100
else
RequiredExp = Level * 100
save5:SetAsync(player.UserId, 0)
end

local coinsValue = Instance.new("IntValue", player)
coinsValue.Name = "Level"
coinsValue.Value = Level

local Exp = Instance.new("IntValue", player)
Exp.Name = "Exp"
Exp.Value = Exp

local RequiredExp = Instance.new("IntValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Level * 100

-- Level Up and Exp --

Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0

Level += 1
RequiredExp.Value = Level * 100
end
end)
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.Level.Value
save3:SetAsync(player.UserId, value)
print("Saved data for "..player.Name)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local value = player.Level.Value

if value ~= nil then
print("Found data to save for "..player.Name.."!")
save3: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 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 = ''

if MPS:UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
player.Coins.Values = player.Coins.Value *2
end
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)

game.Players.PlayerRemoving:connect(function(player)

-------------Sets the deaths once the player joins------------------------------
save2:SetAsync(player.UserId, player.Rounds.Value)
------------------------------------------------------------------
end)
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)

char.Humanoid.Died:connect(function()
player.Rounds.Value = player.Rounds.Value + 1

end)
end)
end)