local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Stats")
game.Players.PlayerAdded:Connect(function(plr)
local brainAmount = plr.PlayerGui:WaitForChild("BrainAmountGUI").IntValue
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local money = Instance.new("NumberValue")
money.Name = "Money"
money.Parent = leaderstats
local moneyValue = data:GetAsync(plr.UserId .. "-Money")
local brainValue = data:GetAsync(plr.UserId .. "-Brain")
if moneyValue ~= nil then
plr.leaderstats.Money.Value = moneyValue
end
if brainValue ~= nil then
brainAmount.Value = brainValue
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local brainAmount = plr.PlayerGui:WaitForChild("BrainAmountGUI").IntValue
local moneySuccess, moneyErr = pcall(function()
data:SetAsync(plr.UserId .. "-Money", plr.leaderstats.Money.Value)
end)
if moneyErr then
print("Money Error")
end
local brainSuccess, brainErr = pcall(function()
data:SetAsync(plr.UserId .. "-Brain", brainAmount.Value)
end)
if brainErr then
print("Brain Error")
end
end)
Script inside ServerScriptStorage