Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to reduce the risk of losing data?

Hi, I'm trying to make a datastore that stores values with weapons name on it. I put these values in a different folder instead of backpack is because I'm letting the player access it in another way. This is what I got after reading post on the roblox devforum, watching videos and looking at the developer.roblox.com page. I've seen on the devforum that they suggest that I should use Datastore2 but I'm not sure if it work for my issue. They also told me to use UpdateAsync in my datastore script to reduce the risk of losing data but I'm not sure how to apply it to my script as they only have examples with numbers. I've tried this script and it work fine but after 3 try, 2 of the try lost one of the weapon value in the in the PlrWeapons folder and there was this error " DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 185862361".

local datastore = game:GetService("DataStoreService"):GetDataStore("WeaponStorage")
local rep = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(plr)
	local chest = Instance.new("Folder")
	chest.Parent = plr
	chest.Name = "PlrWeapons"
	
	local stat
	local success , erro = pcall(function()
		stat = datastore:GetAsync(plr.UserId)
	end)
	
	if stat and success then
		for i,v in pairs(stat) do
			pcall(function()
				if rep.Weapons:FindFirstChild(v)then
					local tag = Instance.new("BoolValue")
					tag.Parent = chest
					tag.Name = v
				end
			end)
		end
	else
		local tag = Instance.new("BoolValue")
		local tag2 = Instance.new("BoolValue")
		local tag3 = Instance.new("BoolValue")
		tag.Name = "WoodenSword"
		tag2.Name = "WoodenSpear"
		tag3.Name = "WoodenBow"
		tag.Parent = chest
		tag2.Parent = chest
		tag3.Parent = chest
	end
	
	chest.ChildAdded:Connect(function()
		local weapons = {}
		for i,v in pairs(plr.PlrWeapons:GetChildren())do
			table.insert(weapons, v.Name)
		end
		local success, err = pcall(function()
			datastore:SetAsync(plr.Id, weapons)
		end)
	end)	
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local weapons = {}
	for i,v in pairs(plr.PlrWeapons:GetChildren())do
		table.insert(weapons, v.Name)
	end
	local success, err = pcall(function()
		datastore:SetAsync(plr.UserId, weapons)
	end)
	if err then
		warn(err)
	end
end)

game:BindToClose(function()
	for i, plr in pairs(game.Players:GetPlayers()) do
		local weapons = {}
		for i,v in pairs(plr.PlrWeapons:GetChildren())do
			table.insert(weapons, v.Name)
		end
		local success, err = pcall(function()
			datastore:SetAsync(plr.UserId, weapons)
		end)
		if err then
			warn(err)
		end
	end
end)

Please help me as this would help me make datastore for other strings in my game. Thank you!

1 comment

0

You may wish to look into https://devforum.roblox.com/t/save-your-player-data-with-profileservice-datastore-module/667805 which can help with preventing data loss

1 answer

Can you comment all the lines in the script, where you are saving and how you are saving and intervals of time you are saving. The thing you mentioned is the warning that the data is saving too often and in the interval before 60 sec.

6 comments

0

Also, it might be showing the line, which is creating the error

0

Also, in Line 35 to 42, why are you saving the data when you are saving it when the player is leaving or the server is getting closed

0

Where do you think I could add the 60s wait?, I could remove the Players.PlayerRemoving part but I'm also looking for how to use UpdateAsync

0

Well, I don't see anywhere to add wait(60) bcz you are savng at intervals. Just try to remove code from line 35 to 42, where you are saving the exact data when the player is leaving

0

*you are not saving anywhere at intervals

0

so no use of wait(60)

This discussion is preserved as it was. New answers, comments, and votes are closed.