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

Is there any problems with my data saving script? Its for my tower defense game

Please check it its for a tower defense game it kept saying

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1012559870

workspace:FindFirstChild(player.Name..player[v.Name].Value) local data = game:GetService("DataStoreService"):GetDataStore("TowerDataStore") function save(plr)

local saveData = {}
for i, v in pairs(plr:GetChildren())do
	if v:IsA("StringValue") then
		saveData[v.Name] = v.Value
	end
end
data:SetAsync(plr.UserId, saveData)

end

game.Players.PlayerAdded:Connect(function(plr) for i = 1, 5 do local x = Instance.new("StringValue", plr) x.Name = "Tower"..tostring(i) x.Value = "Empty" end local getData local success, errorm = pcall(function() getData = data:GetAsync(plr.UserId) end) if success then if getData then for i, v in pairs(getData) do plr:FindFirstChild(i).Value = v end end end end) game:BindToClose(function() for _, v in pairs(game.Players:GetChildren()) do save(v) end end) game.Players.PlayerRemoving:Connect(function(plr) save(plr) end)


Check this too

local player = game.Players.LocalPlayer

for i, v in pairs(script.Parent:GetChildren()) do if v:IsA("Frame") and v:FindFirstChild("Place") then v:FindFirstChild("Place").MouseButton1Down:Connect(function() if not player[v.Name].Value ~= "Empty" then if script.Placing.Value == nil then local mouse = player:GetMouse() script.Placing.Value = v

				spawn(function()
					local t = false
					while script.Placing.Value ~= nil do
						wait()
						if t == false then
							local tower = game:GetService("ReplicatedStorage").Towers:FindFirstChild(player[v.Name].Value)
							if tower then
								tower.Name = player.Name..player[v.Name].Value
								tower:Clone().Parent = workspace
							end
						end
						if workspace:FindFirstChild(player.Name..player[v.Name].Value) then
							workspace:FindFirstChild(player.Name..player[v.Name].Value).HumanoidRootPart.BodyPosition.Position = mouse.Hit.p
						end
					end
				end)
			elseif script.Placing.Value ~= nil and script.Placing.Value == v then
				script.Placing.Value = nil
			end
		end
	end)
	v.TowerName.Text = player[v.Name].Value
	
	player[v.Name].Changed:Connect(function()
		v.TowerName.Text = player[v.Name].Value
	end)
end

end

3 comments

0

I know its a bit messy but please check

0

For starters, you should ALWAYS pcall your Set/Update/GetAsync scripts, just incase it doesnt save. Also, what line are u getting the error from?

0

Did you turn'd API Services ON? Your script(s) are supporting services.

1 answer

Data Stores have a certain cool down, if you will, which only allows a certain amount of data to be stored at a time. A better option would be to save the data either when the player leaves or a auto save that happens after a said amount of time.

Another good idea may be to add a separate folder inside of the player which holds said data. For example:
game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new('Folder')
	Folder.Parent = player
end)

With this you can have strings inside of that which hold the values of the towers. After that there is the data store which can be done like this:

local DataStoreService = game:GetService('DataStoreService')
local DataSave = DataStoreService:GetDataStore('DataSave')

game.Players.PlayerAdded:Connect(function(player)
	
	local Folder = Instance.new('Folder')
	Folder.Parent = player
	
	local SavedData
	local success, errormessage = pcall(function()
		SavedData = DataSave:GetAsync(player.UserId..'-Tower_Data')
	end)
	
	if success then
		-- Add Tower String Value And Table Position Here Like: Folder.TOWERNAME.Value = data[1]
	else
		warn(errormessage)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		DataSave:SetAsync(player.UserId..'-Tower_Data', -- Save Data Here)
	end)
	
	if success then
		print("Success! Players Tower Data Has Been Saved!")
	else
		warn(errormessage)
	end
	
end)

Any More Questions Just Comment!

-- WolfTamer894

3 comments

0

Thx bro

0

But it does not work

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