Datastore Tutorial (Reduce data loss!)

Nice tutorial but please use task.wait() wait is outdated

3 Likes

You should do a tutorial on Profile Service. These types of data stores just reduce data loss, but what about REMOVING data loss?

2 Likes

I do like to use ProfileService, but this tutorial just focuses on Roblox’s default Datastore implementation. I agree Profile Service is more secure but sometimes it can take a while for data to load :slight_smile:

Using profileservice does not “remove data loss”, its only enemy is stuff like pet cloning via trading etc. not data loss


Generalized loops also work well, using ipairs or pairs does no difference.

3 Likes

ipairs is actually faster then pairs. ipairs should only be used when all objects that are being looped through are the same type.

because they are iterated, generalized pairs will either iterate pair or pairs if its a dictionary

also micro optimization is not good

edit

Edit: i hardly even call this optimization. you are only saving 0.01 seconds using ipairs

0.04	pairs
0.03	ipairs

code

local clock = os.clock
local function benchmark(benchmarks, times)
   for i,v in pairs(benchmarks) do
      local first = clock()
      for i = 1, times do
         v()
      end
      print(clock() - first, i)
   end
end
benchmark({
   ["pairs"] = function()
      for _,v in pairs({"hi", "mango"}) do
         v = nil
      end
   end,
   ipairs = function()
      for _,v in ipairs({"hi", "mango"}) do
         v = nil
      end
   end
}, 100000)

Just a quick suggestion when benchmarking, try to make the benchmark as light as possible to narrow in on what needs to be tested. I made a post about pairs and ipairs a while ago and benchmarked the two:

If we use that benchmark we can see the difference between the two is actually 0.000000000000014551915228 per iteration.

So you’re absolutely correct, it’s micro optimization; it’s just even more micro than what was shown.

2 Likes

I think they did, by using the DataId in the load function and checking it while saving.

2 Likes

It doesn’t save my data. :confused:
I followed everything I think the tutorial was not completed.

1 Like

You should try DataStore2 it’s easier to learn and doesn’t have any data loss (if used correctly)
Tutorial
Module

2 Likes

Did you get any error messages in the output?
Sorry for the late reply.

ProfileService works too and is more modern

2 Likes

I don’t even remember but I tried to follow the tutorial. It wasn’t easy, I had to cut somethings because I was not making an obby so I didn’t want to save the position of the player.

1 Like

I don’t know how to use it sadly.

2 Likes

Oh, I made a tutorial about it where you don’t have to set it up the repetitive way, unlike what YouTubers teach you to do:

I’m sorry about that, which part can you not get to work? :frowning:

Saving and giving the data I think. I had to remove a part of the script because I am not making an obby.

Datastore 2 has progress loss issues for some reason, even the latest version

1 Like

You may not be using it right.

Is this a correct way of using? I’m very new to ds2 and it causes progress loss (mostly on shutdowns) for some reason.

game.Players.PlayerAdded:Connect(function(plr)
	local DataStore = DataStore2("Data", plr)
	local UserDataTable = DataStore:Get(Template)
	
	SharedDataStorage[plr] = UserDataTable

	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"	
	local Coin = Instance.new("NumberValue", leaderstats)
	
	local Methods = Instance.new("Folder", plr)
	Methods.Name = "Methods"

	
	Coin.Value = UserDataTable.Coins
	Coin:GetPropertyChangedSignal("Value"):Connect(function()
		if SharedDataStorage[plr] then
			SharedDataStorage[plr]["leaderstats"]["Coins"] = Coin.Value 
		end
	end)
	
	for i,z in pairs(SharedDataStorage[plr].Methods) do
		local item = Instance.new("StringValue", Methods)
		item.Name = z
	end

	Methods.ChildAdded:Connect(function(c)
		table.insert(SharedDataStorage[plr].Methods, c.Name)
		UpdateAllFolders:Fire(plr)
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local DataStore = DataStore2("Data", plr)
	DataStore:Set(SharedDataStorage[plr])
	SharedDataStorage[plr] = nil
end)

game:BindToClose(function()
	if game:GetService("RunService"):IsStudio() then return end

	for _,plr in pairs(game.Players:GetPlayers()) do
		local DataStore = DataStore2("DataKey", plr)
		DataStore:Set(SharedDataStorage[plr])
		SharedDataStorage[plr] = nil
	end
end)