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

Datastore problem not saving after 30 times changes?

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CoinsSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
	local ls = Instance.new("Folder", plr)
	ls.Name = "leaderstats"
	local st = Instance.new("StringValue")
	st.Name = "Coins"
	st.Parent = ls
	st.Value = 0

 st.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, st.Value)
 
 
 st.Changed:connect(function()
 ds1:SetAsync(plr.UserId, st.Value)

end)
end)

11:52:19.993 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 38381653 (x21)

after x30 requests are sent this just drops the saves, how do i make this infinite? if its even possible.

4 comments

0

Roblox limits how many request Datastore can take, maybe make it just save when the player leaves?

0

Too much request make Datastore drop. You can save when player leave and server close. or use DataStore2

0

I dont know if this is the best way, but I usually have a different table in module script that saves the value and player who requested, and will save the players data no matter if player is in the game or not. However, use still should save data when player leaves as this might drop if actual server closes due to crashes or when you are the last player to leave.

0

Perhaps you could update it everytime the player collects a certain amount. Then any others which aren't saved, can be saved as player leaves. That way you don't have constant requests to save.

2 answers

✓ Accepted answer

How do i save when a player leaves?

local DataStoreService = game:GetService("DataStoreService")
local saveDataStore = DataStoreService:GetDataStore("ChangeThis")

-- When the player join load the saved stats
game.Players.PlayerAdded:connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	-- example with 2 data (cash & kill) you can add more if you want
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 10
	cash.Parent = leaderstats
	
	local kill = Instance.new("IntValue")
	kill.Name = "Kill"
	kill.Value = 0
	kill.Parent = leaderstats
	
	-- Get the saved data
	local data = saveDataStore:GetAsync(plr.UserId)
	if data then
		for i, v in pairs(leaderstats:GetChildren()) do
			v.Value = data[v.Name]
		end
	end
end)

-- When the player leave save the data
game.Players.PlayerRemoving:connect(function(plr)
	local leaderstats = plr:FindFirstChild("leaderstats")
	if leaderstats then
		local saveData = {}
		for i, v in pairs(leaderstats:GetChildren()) do
			saveData[v.Name] = v.Value
		end
		saveDataStore:SetAsync(plr.UserId, saveData)
	end
end)

1 comment

0

Tysm!

There's too many requests, you can save data in intervals of 5-10mins and when the player leaves.

1 comment

0

How do i save when a player leaves?

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