I’ve got my leaderstats setup, but for some reason it doesn’t load when someone joins.
local DataStoreService = game:GetService("DataStoreService")
local moneyDS = DataStoreService:GetDataStore("moneyDS")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Money"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = moneyDS:GetAsync(plr.UserId.."-cash")
end)
if success then
cash.Value = data or 1500
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
moneyDS:SetAsync(plr.UserId.."-cash", plr.leaderstats.Money.Value)
end)
if success then
print("Data successfully saved")
else
print("Error when saving data")
warn(errormessage)
end
end)