-- // Configurations
local DataName = "BLABLA" -- Edit this
local FolderName = "leaderstats" -- Edit this
local FolderType = "Folder" -- Edit this
local StatsName1 = "Name1" -- Edit this
local StatsValue1 = 0 -- Edit this
local StatsType1 = "NumberValue" -- Edit this
local StatsName2 = "Name2" -- Edit this
local StatsValue2 = 0 -- Edit this
local StatsType2 = "NumberValue" -- Edit This
-- // End of configurations
local DataStoreService = game:GetService("DataStoreService")
local statsStore = DataStoreService:GetDataStore(DataName)
local PlayersService = game:GetService("Players")
function saveStats(PlayerFunction)
local leaderFolder = Instance.new(FolderType, PlayerFunction)
leaderFolder.Name = FolderName
local statsValue1 = Instance.new(StatsType1, leaderFolder) -- Use this "NumberValue" , leaderFolder instead of .Parent, to make the code more stable
statsValue1.Name = StatsName1
local statsValue2 = Instance.new(StatsType2, leaderFolder)
statsValue2.Name = StatsName2
local prlKey= "Player_" .. PlayerFunction.UserId
local oldData
local foundData,newplr = pcall(function()
oldData = statsStore:GetAsync(prlKey)
end)
if foundData and oldData ~= nil then
statsValue1.Value = foundData[1]
statsValue2.Value = foundData[2]
print("Data loaded for: " ..PlayerFunction.Name)
else
statsValue1.Value = StatsValue1
statsValue2.Value = StatsValue2
print("New data for: " ..PlayerFunction.Name)
end
end
PlayersService.PlayerAdded:Connect(function(PlayerAdded)
local succesLoaded,ErrorLoaded = pcall(function()
saveStats(PlayerAdded)
end)
if succesLoaded then
print("Data loaded for: " ..PlayerAdded.Name)
else
print("Data not loaded: " ..PlayerAdded.Name)
end
end)
PlayersService.PlayerRemoving:Connect(function(PlayerRemoved)
local leaderstats = PlayerRemoved:FindFirstChild(l"FolderName") -- EditThis
local prlKey= "Player_" .. PlayerRemoved.UserId
local valueToSave = {
leaderstats:FindFirstChild("StatsName1"); -- Edit this
leaderstats:FindFirstChild("StatsName2"); -- Edit this
}
local succesSaved,ErrorSaved = pcall(function()
statsStore:SetAsync(prlKey,valueToSave)
end)
if succesSaved then
print("Data saved! for: "..PlayerRemoved.Name)
else
print("Data not saved! for: "..PlayerRemoved.Name)
end
end)
game:BindToClose(function()
for _, allplayers in pairs(PlayersService:GetChildren()) do
local succesSaved,ErrorSaved = pcall(function()
saveStats(allplayers)
end)
if succesSaved then
print("Data saved for:".. allplayers.Name)
else
print("Data not saved for:".. allplayers.Name)
end
end
end)
I know what i can EDIT ONLY BY SERVER. Every data is UPDATED BY SERVER not BY CLIENT
Okay maybe that studio glitch, because when i reopen studio new data saves
This script is working fine for me, I know because I wrote most of it.
Studio glitch as i understand, because when i re-open studio everything fine
Lemme try check it in game not in studio
Okay nvm even in game nothing saves
Idk it like have a biiiig cooldown, because yesterday i had other data today a new one, but i can’t save data again in same time
Wait i that a warn not a success that means data didn’t save…
IDK what’s the reason of cooldown, but when i saved first data i got error “too much datastore request. Other request will be deleted”
Yeah seems datastore get very much requests and this is a reason why data don’t save
You definitely can’t save 4 values in one datastore, here’s the format:
Key:
Value:
Of course, you could use a table, such as this:
local dataToSave = {
player.leaderstats.Money.Value;
player.leaderstats.Clicks.Value;
player.leaderstats.Rebirths.Value
}
dataStore:SetAsync("Data_"..player.UserId, dataToSave)
That would generally save all the information. I hope this helped a little!
It’s already being saved as a table, his issue is an infinite yield on an instance which doesn’t exist.
I already fixed that this didn’t help data still work strange
I do not know what to do everything fine, but data still saves strange
Here is a error i think this is a problem of datastore
This is because you’re entering/exiting the game too frequently.
Okay nvm i got the problem, one of data breaks datastore
player:WaitForChild("PlayerGui").Stats.RCAmount.Value
this part break everything
I removed that part and now everything fine, but i need that part
Everything must be fine. Path is correct