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

Data Store Service problem?

I'm trying to make a game but I will not going into details. Anyway, I'm trying to make a system that requires saving and getting a table from the Data Store Service. I have created a new place just to test this, and I got a problem. I have a server script for storing the data, local script for sending the table to the data store script, and another local script that creates the data. I know it sounds a bit confusing but when you will see the scripts I hope everything will become more clearly. My problem is (at list what i think it is) that most of the time the data isn't being saved. I tried to see how can I fix the problem and found out that every time that I change the player key (the unique key that stores each player's data) or the data store key (:GetDataStore(This)) I get a warning in the console:

Request was throttled. Try sending fewer requests. Key = [key]

and the data being saved. This is the only time that the game saves the data. I think it's a bug or something but I really need that system so if any one can help I would very appreciate it :)

The scripts:

Data store script:

--Data store SERVER script, Parent: Workspace


--Get services
local DSService = game:GetService('DataStoreService'):GetDataStore('@1F6=mX')

local Workspace = game:GetService('Workspace')

local Players = game:GetService('Players')

local ReplicatedStorage = game:GetService('ReplicatedStorage')

--Make data save folder
local DataSaveFolder = Instance.new('Folder', ReplicatedStorage)
DataSaveFolder.Name = "DataSaveFolder"

--Player is joining the game
Players.PlayerAdded:Connect(function(player)
	
	local uniqueId = 'id-'..player.userId --Player unique id
		
	local tableData = {} --Table data
	
	--Insert default data into table for a case that the player has no data
	for index, value in pairs(ReplicatedStorage.DefaultTableData:GetChildren()) do
		table.insert(tableData, value.Value)
	end
	
	local GetSaved = DSService:GetAsync(uniqueId) --Stores the player data on get saved 
		
	
	if	GetSaved then --Checks if player has any data
			
		tableData = GetSaved --If true pull the exicting data 
		
		
		--Debug	Start
		print("Debug - The player has past data. Table:")
		for i,v in pairs(tableData) do
			print("Debug - #"..i.." - "..v)
		end		
		--Debug End			
			
	else
			
		DSService:SetAsync(uniqueId, tableData)--If false save the default data for a new player
		
		--Debug	Start	
		print("Debug - The player has no past data. Table:")
		for i,v in pairs(tableData) do
			print("Debug - #"..i.." - "..v)
		end		
		--Debug	End
			
	end	
	
end)

--Player is leaving the game
Players.PlayerRemoving:Connect(function(player)
	
	local uniqueId = 'id-'..player.userId --Player's unique id
	
	local dataPullRF = ReplicatedStorage.Remote.RemoteFunctions.PlayerLeavingTablePullRF

	local tableDataToSave = dataPullRF:InvokeClient(player)
	
	local GetSaved = DSService:GetAsync(uniqueId)
	
	--Debug Start
		print("Debug - The player leaved the game. Table to save:")
		for i,v in pairs(tableDataToSave) do
			print("Debug - #"..i.." - "..v)
		end		
	--Debug End
	
	DSService:SetAsync(uniqueId, tableDataToSave)
	
end)

Data send script:

--Data send LOCAL script, Parent: StarterGui


--Get Services
local Workspace = game:GetService('Workspace')

local Players = game:GetService('Players')

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local DataSaveFolder = ReplicatedStorage:WaitForChild('DataSaveFolder')

local tableGiveRF = ReplicatedStorage.Remote.RemoteFunctions.PlayerLeavingTablePullRF


--Give data function
local function SendTable()
	print("Debug - GiveTable function has been activated")
	local tableToSend = {}--Create table to give
	
	for index, value in pairs(DataSaveFolder:GetChildren()) do --Adds the values to the table from the data save folder
		
		table.insert(tableToSend, value.Value)
		
	end
	
	if tableToSend == nil then --If there was a problem and the table to give is nil
		print("Debug - The table is nill (local script), fixing it!")
		for index, value in pairs(ReplicatedStorage.DefaultTableData:GetChildren()) do --Adds the values to the table from the default data save folder
			
			table.insert(tableToSend, value.Value)
			
		end	
		
	end
	
	--Debug Start
		print("Debug - Return, Table to give:")
		for i,v in pairs(tableToSend) do
			print("Debug - #"..i.." - "..v)
		end		
	--Debug End
	return tableToSend
	
end

tableGiveRF.OnClientInvoke = SendTable

Data set script:

--Data set LOCAL script, Parent: StarterGui


--Get Services
local Workspace = game:GetService('Workspace')

local Players = game:GetService('Players')

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local DataSaveFolder = ReplicatedStorage:WaitForChild('DataSaveFolder')

local tableGiveRF = ReplicatedStorage.Remote.RemoteFunctions.PlayerLeavingTablePullRF

--Make data
for i = 8, 20 do --I'm changing this every time just to check if it saves the new data
	
	local data = Instance.new("IntValue", DataSaveFolder)
	data.Value = i
	
end
 

1 answer

You are sending too many requests in Data Store Service causing it to stop the script.

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