local currencyName = "Money"
local Datastore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:Async(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data Loaded")
else
currency.Value = 50
print("New Player To The Game")
end
end)
game.Players.Removing:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(Id,player.leaderstats [currencyName] .Value)
end)
game:BindToClose(function()
for i, player in pairs (game.Players:GetPlayers()) do
if player then
player:Kick("This Server Has Started To Shutdown. Please do rejoin")
end
end
wait(5)
end~~~~~~~~~~~~~~~~~