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

DataStore - Try sending fewer requests?

Yo, so I've made a bool value inside leaderstats script that I copied from a tutorial. The Bool Value says whether or not a player owns a vehicle. I have two values, Money and the Vehicle. The vehicle saves, however the money does not. Any help is appreciated.

Error: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Money-226030996

local currencyName = "Money"
local Car1Owned = "Car1Owned"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats" 
	folder.Parent = player
	
	local currency = Instance.new("IntValue")
	currency.Name = currencyName
	currency.Parent = folder
	
	local Owned = Instance.new("BoolValue")
	Owned.Name = Car1Owned
	Owned.Parent = folder
	
	local ID = currencyName.."-"..player.UserId

	
	local savedData = nil
	
	pcall(function()
		savedData = DataStore:GetAsync(ID)
	end)
	
	if savedData ~= nil then
		Owned.Value = savedData
		currency.Value = savedData
		print("Data loaded")
	else
		-- new player
		currency.Value = 1000
		print("New player to the game")
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local ID = currencyName.."-"..player.UserId
	DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
	DataStore:SetAsync(ID,player.leaderstats[Car1Owned].Value)
end)

1 comment

1

You’re overwriting it

1 answer

✓ Accepted answer

You are saving Currency and Owned on the same key overwriting whichever saves first(in this case currency gets overwritten), you are gonna need to have two different ID's(keys) to save them on, i.e

Note: You are gonna have to change the GetAsync part to use two different ID's too

local CurrencyID = currencyName.."-"..player.UserId
local Car1OwnedID = Car1Owned.."-"..player.UserId
DataStore:SetAsync(CurrencyID,player.leaderstats[currencyName].Value)
DataStore:SetAsync(Car1OwnedID,player.leaderstats[Car1Owned].Value)

see Datastore

Don't forget to mark my answer as the solution and upvote it if it solved your problem :)

If you need more help please post a comment

2 comments

0

Thanks mate! Appreciate the help.

0

np

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