local DataStoreToKeep = dss:GetDataStore(“TypeWhatYouWantHere”)
game.Players.PlayerAdded:Connect(function(player)
local is = Instance.new(“Folder”,player)
is.Name = “leaderstats”
local money = Instance.new("IntValue",is)
money.Name = "Money"
money.Value = 0
local data
local success, errormessage = pcall (function()
data = DataStoreToKeep:GetAsync(player.UserId.."~money")
end)
if success then
money.Value = data
else
warn(errormessage)
end
local success, errormessage = pcall(function()
DataStoreToKeep:SetAsync(player.UserId.."~money",player.leaderstats.Money.Value)
end)
if success then
else
warn(errormessage)
end
Leaving Studio Is The Same As A Shutdown. It Uses A Function Known As “BindToClose”. For this to 100% Work, You Need To Go To Game Settings And Enable The Setting Called “Enable Studio Access To API Services”. I Suggest That You Completely Copy And Paste The Following:
local dss = game:GetService(“DataStoreService”)
local DataStoreToKeep = dss:GetDataStore(“TypeWhatYouWantHere”)
game.Players.PlayerRemoving:Connect(function(player)
local function Set(player)
local success, errormessage = pcall(function()
DataStoreToKeep:SetAsync(player.UserId.."~money",player.leaderstats.Money.Value)
end)
if success then
else
warn(errormessage)
end
end
game.Players.PlayerAdded:Connect(function(player)
local is = Instance.new(“Folder”,player)
is.Name = “leaderstats”
local money = Instance.new("IntValue",is)
money.Name = "Money"
money.Value = 0
local data
local success, errormessage = pcall (function()
data = DataStoreToKeep:GetAsync(player.UserId.."~money")
end)
if success then
money.Value = data
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(Set)
game:BindToClose(function()
for i, v in next, game.Players:GetChildren() do
if v then
Set(v)
end
end
end)
- i fixed it for you … use this .
*you are using “ and ”. you should use " and " .
local dss = game:GetService("DataStoreService")
local DataStoreToKeep = dss:GetDataStore("TypeWhatYouWantHere")
-- Get Player MONEY Data
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "MONEY"
money.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = DataStoreToKeep:GetAsync(player.UserId.."_money")
end)
if success then
player.leaderstats.MONEY.Value = data
else
warn(errormessage)
end
end)
-- Save player MONEY Data When Leave The Server
game.Players.PlayerRemoving:Connect(function(player)
local data
local success, errormessage = pcall(function()
data = DataStoreToKeep:SetAsync(player.UserId.."_money", player.leaderstats.MONEY.Value)
end)
if success then
player.leaderstats.MONEY.Values = data
else
warn(errormessage)
end
end)