local ds = game:GetService("DataStoreService")
local rpDS = ds:GetDataStore("RPname")
local cashDS = ds:GetDataStore("CashDS")
wait(1)
game.Players.PlayerAdded:Connect(function(plr)
plr.RPname.Value = rpDS:GetAsync(plr.UserId) or plr.Name
plr.leaderstats.Cash.Value = cashDS:GetAsync(plr.UserId) or 200
end)
game.Players.PlayerRemoving:Connect(function(plr)
local saved, msg = pcall(function()
cashDS:SetAsync(plr.UserId, plr.Leaderstats.Cash.Value)
end)
if not saved then
for i = 1, 10 do
warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
wait(5)
cashDS:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
end
end
local saved, msg = pcall(function()
rpDS:SetAsync(plr.UserId, plr.RPname.Value)
end)
if not saved then
for i = 1, 10 do
warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
wait(5)
rpDS:SetAsync(plr.UserId, plr.Character.Head.RP.TextLabel.Text)
end
end
end)
Server script in server script service.
No errors.
local ds = game:GetService("DataStoreService")
local rpDS = ds:GetDataStore("RPname")
local cashDS = ds:GetDataStore("CashDS")
wait(1)
game.Players.PlayerAdded:Connect(function(plr)
plr.RPname.Value = rpDS:GetAsync("Text-"..plr.UserId) or 0
plr.leaderstats.Cash.Value = cashDS:GetAsync("Cash-"..plr.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(plr)
local saved, msg = pcall(function()
cashDS:SetAsync("Cash-"..plr.UserId, plr.leaderstats.Cash.Value)
end)
if not saved then
for i = 1, 10 do
warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
wait(5)
cashDS:SetAsync("Cash-"..plr.UserId, plr.leaderstats.Cash.Value)
end
end
local saved, msg = pcall(function()
rpDS:SetAsync("Text-"..plr.UserId, plr.Character.Head.RP.TextLabel.Text)
end)
if not saved then
for i = 1, 10 do
warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
wait(5)
rpDS:SetAsync("Text-"..plr.UserId, plr.Character.Head.RP.TextLabel.Text)
end
end
end)
the reason why it’s 0 because if its 200 user id and above but how about the users who are below that id cant load their data