local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
game.Players.PlayedAdded:Connect(function(plr)
wait()
local plrkey = "Id_"..plr.userid
local savevalue = plr.leaderstats.Clicks
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
savevalue.Value = GetSaved(1)
else
local NumbersForSaving = {savevalue.Value}
DS:GetAsync(plrkey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.UserId, {plr.leaderstats.Clicks.Value})
end)
Ok heres the fix I guess.
Also make sure that studio access to api services is enabled.
local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "Id_"..plr.userId
local savevalue = plr.leaderstats.Clicks
local Success, ErorrMsg = pcall(function()
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
savevalue.Value = GetSaved
else
local NumbersForSaving = savevalue.Value
DS:GetAsync(plrkey, NumbersForSaving)
end
end)
if Success then
print("Success loading data")
else
warn(ErorrMsg)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("Id_"..plr.UserId, plr.leaderstats.Clicks.Value)
end)