local DataSave = game:GetService("DataStoreService")
local DataSaver = DataSave:GetDataStore("DataSaver1")
local bruh = {ServerWins = 0, Wins = 0}
local function Stats(Players)
local leaderstats = Instance.new("Folder", Players) --Create a new leaderstats
leaderstats.Name = "leaderstats"
local ServerWins = Instance.new("IntValue", leaderstats)
local Wins = Instance.new("IntValue", leaderstats)
ServerWins.Name = "ServerWins"
ServerWins.Value = bruh.ServerWins
Wins.Name = "Wins"
Wins.Value = bruh.Wins + bruh.ServerWins
Key = "PlayerID" .. Players.UserId-- Set a key, we need this to be global because it will be used later
leaderstats.Changed:Connect(function()
DataSaver:SetASync(Key, Wins.Value)
end)
end
local GetDataSaver
print("bruh")
Done, Error = pcall(function()
GetDataSaver = DataSaver:GetAsync(Key) or 0 --Get A sync to save
if Done == true then
bruh.Wins.Value = GetDataSaver
print("Succesful")
else
return Error
end
print("ok")
end)
game.Players.PlayerAdded:Connect(Stats)-- Everytime the player join the game, they will get a leaderstats and their previous win
game.Players.PlayerRemoving:Connect(function(Players)
local Done, Error = pcall(function()
DataSaver:SetAsync(Key, Players.leaderstats.Wins.Value)
end)
print("bruh")
end)
This script is located inside ServerScriptService btw
