Prevent from loading in data too much?

So I have this datastore

local DataStore2 = require(1936396537)

local Settings = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))

local gui = nil

game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ToDatastore").OnServerEvent:Connect(function(plr,gui)
	print("got first event")
	gui = gui
		for i,v in pairs(Settings) do
			local datastore = DataStore2(i,plr)
			local where = v.Where
			if v.Where ~= "Player" then
				if plr:findFirstChild(v.Where) then
					where = plr[v.Where]
				else
					local folder = Instance.new("Folder",plr)
					folder.Name = v.Where

					where = folder
				end
			end

			if v.Where == "Player" then
				where = plr
			end
			--// Creates the Value
			local val = Instance.new(v.What,where)
			val.Name = i
			val.Value = v.Value

			--// Loading
			if datastore:Get() ~= nil then
			val.Value = datastore:Get()
			if val.Name == "DoneTest" then
			local typeofe = "StartIntro"
				gui.Event:FireClient(plr,typeofe)
				gui = nil
			print("sent 2nd event")
			end
			end

			--//Saving
		val.Changed:connect(function()
		datastore:Set(val.Value)
		end)
		print("fart")
	end
end)
print("fart3")

And when I do everything in studio it works fine. but in an actual game, it takes 2-3 minutes to load in, and even longer for the next person after, it keeps giving an error of “DataStore request was added to queue, if request queue fills, furthur requests will be dropped. try sending fewer requests” so idk what to do

1 Like