I need the best datastore script please help me ( not datastore2 )

I am in need for a good datastore with no dataloss but not datastore2

Wrong category. For this you’ll need to hire a scripter in #collaboration:recruitment or search in #resources:community-resources

If you are a bit more advanced Firebase is a great free option. [Open Source] FirebaseService

You cannot just ask someone to give you a script in this category mate.

1 Like

If you need a script then try this:

local tries = 0
local success, errormessage
repeat
     success, errormessage = pcall(function()
          --save the data
     end
     if success then
          print("success!")
          break
     else
          print("errormessage: "..errormessage)
     end
     tries = tries + 1
until success or tries == 3

That should prevent most dataloss

how would i use it here

local PlayerStatsDS = game:GetService(“DataStoreService”):GetDataStore(“Test4”)

game.Players.PlayerAdded:Connect(function(NP)

local Key = NP.UserId

local GetSave = PlayerStatsDS:GetAsync(Key)

local PSF = Instance.new("Folder", NP)
PSF.Name = "PlayerData2"

local StatsFolder = script.Stats

for _, S in pairs(StatsFolder:GetChildren()) do
	local NS = Instance.new(S.ClassName, PSF)
	NS.Name = S.Name
	NS.Value = S.Value
end

if GetSave then
	for n, Stat in pairs(PSF:GetChildren()) do
		Stat.Value = GetSave[n]
	end
else
	local STS = {}
	for _, Stat in pairs(StatsFolder:GetChildren()) do
		table.insert(STS, Stat.Value)
	end
	PlayerStatsDS:SetAsync(Key, STS)
end

end)

game.Players.PlayerRemoving:connect(function(OP)

local Key = OP.UserId

local StatsFolder = OP.PlayerData2

local STS = {}
for _, Stat in pairs(StatsFolder:GetChildren()) do
	table.insert(STS, Stat.Value)
end
PlayerStatsDS:SetAsync(Key, STS)

end)

if game:GetService(“RunService”):IsStudio() then
else
game:BindToClose(function()
print(“Saving all data”)
wait(10)
print(“Saved and closed server.”)
end)
end

place my script instead of that, with PlayerStatsDS:SetAsync(Key, STS) where I have the comment
--save the data

You can also use this script where you want to load the data.

If this is what you want then mark it as the solution

1 Like

I can give you an idea of how to make a good datastore system, this is how mine works. It retries three times to get data from the player using a pcall, if it still is errored I make a string value inside the player called “DATANOTLOADED”, now inside my set function, if the tag is inside the player then I dont set his data, else if it isnt then I set data. Then if the pcall fails inside the set function I sent a message to my discord webhook. Also I autosave the data after every round

Basically:
I set the data after the player leaves, and when the game is shutdown using :BindToClose() and finally an autosave after every round, and if there is data loss when the player leaves I sent it to my discord webhook

1 Like

can you implement it to my script, please and thank you i am kinda dumb with data

Here you go! This will also make sure you don’t fail when you are loading data. Set this as the answer if that is what you wanted

local Key = NP.UserId

local GetSave = PlayerStatsDS:GetAsync(Key)

local Gtries = 0
local Gsuccess, Gerrormessage
repeat
     Gsuccess, Gerrormessage = pcall(function()
        GetSave = PlayerStatsDS:GetAsync(Key)
     end
     if Gsuccess then
          print("success!")
          break
     else
          print("errormessage: "..Gerrormessage)
     end
     tries = tries + 1
until Gsuccess or Gtries == 3

local PSF = Instance.new("Folder", NP)
PSF.Name = "PlayerData2"

local StatsFolder = script.Stats

for _, S in pairs(StatsFolder:GetChildren()) do
	local NS = Instance.new(S.ClassName, PSF)
	NS.Name = S.Name
	NS.Value = S.Value
end

if GetSave then
	for n, Stat in pairs(PSF:GetChildren()) do
		Stat.Value = GetSave[n]
	end
else
	local STS = {}
	for _, Stat in pairs(StatsFolder:GetChildren()) do
		table.insert(STS, Stat.Value)
	end
	PlayerStatsDS:SetAsync(Key, STS)
end

end)

game.Players.PlayerRemoving:connect(function(OP)


local Key = OP.UserId

local StatsFolder = OP.PlayerData2

local STS = {}
for _, Stat in pairs(StatsFolder:GetChildren()) do
	table.insert(STS, Stat.Value)
end

local tries = 0
local success, errormessage
repeat
     success, errormessage = pcall(function()
          PlayerStatsDS:SetAsync(Key, STS)
     end)
     if success then
          print("success!")
          break
     else
          print("errormessage: "..errormessage)
     end
     wait(2)
     tries = tries + 1
until success or tries == 3

end)

if game:GetService(“RunService”):IsStudio() then
else
game:BindToClose(function()
print(“Saving all data”)
wait(10)
print(“Saved and closed server.”)
end)
end

thank you i will try it out -------

it says to close got “if” i dont think u wrote it right

This is not a good idea if you aren’t yielding at all, if a request fails then your code will just keep retrying until the given number of tries in rapid succession (with the only yield being the GetAsync) and that’ll put your requests in the throttled requests queue quick given multiple requests fail (which is unlikely other than if you’re using it incorrectly or there’s some issue on Roblox’ end) .

Whoops, forgot about the wait(2) in between, I’ll add it

It’s fixed now. Good luck with your game!

(thirty charssss)

1 Like

thank you so much it worked but, shouldnt i add to wait(2) to the pcall when the player joins

Go for it. Or you can do player.CharacterAdded:Wait() which should make sure the character is loaded

okay thank you --------- 30 char

Make sure to follow the guidelines before creating a post.