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

My IntValues on my game wont save?

So I made an OnServerEvent where when u buy something it gives you a value of 1 so it can save your items but when I wrote this script that worked for all my leader stats it didn't work for: Error: DataStore request was added to the queue. If the request queue fills, further requests will be dropped. Try sending fewer requests.

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("PlayerData")



local function onPlayerJoin(player)  -- Runs when players join
local SwordBools = Instance.new("Folder")
SwordBools.Name = "SwordBools"
	SwordBools.Parent = player


	local WoodKnife = Instance.new("IntValue")
	WoodKnife.Name = "OwnWKnife"
	WoodKnife.Parent = player.SwordBools


	local Knife = Instance.new("IntValue")
	Knife.Name = "OwnKnife"
	Knife.Parent = player.SwordBools

	



	local data
	local success,errormsg = pcall(function()
	    data = playerData:GetAsync(playerUserId)
	end)
	if success then
	    if data then
	        WoodKnife.Value = data.OwnWKnife
	        Knife.Value = data.OwnKnife
	else
	    WoodKnife.Value = 0
	        Knife.Value = 0
	end


		
	end

end



local function create_table(player)

	local player_stats = {}

	for _, stat in pairs(player.SwordBools:GetChildren()) do

		player_stats[stat.Name] = stat.Value

	end

	return player_stats

end



local function onPlayerExit(player)  --Runs when players exit



	local player_stats = create_table(player)

	local success, err = pcall(function()

		local playerUserId = "Player_" .. player.UserId

		playerData:SetAsync(playerUserId, player_stats) --Saves player data

	end)



	if not success then

		warn('Could not save data!')

	end

end



game.Players.PlayerAdded:Connect(onPlayerJoin)

game.Players.PlayerRemoving:Connect(onPlayerExit)

1 comment

0

There’s a guide for data stores on this site, you could probably use that

1 answer

try this on lines 28-47

local data
local success,errormsg = pcall(function()
	data = myDataStore:GetAsync(playerUserId)
end)
if success then
	if data then
        WoodKnife.Value = data.OwnWKnife
        Knife.Value = data.OwnKnife
else
	WoodKnife.Value = 0
        Knife.Value = 0
end

3 comments

0

Hey so I tried that and it didn't work but I got a error(Check the edit)

0

I've never seen that error before so I will look at that, but I also realized I made an error in my script, I forgot to add the end to the "if data then" statement

0

Also im confused on lines 47-59, did you ever insert the stat into the table? Its calls to the table to find "stat.Name" but before when you made the table, you never inserted anything there so it is still empty?

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