Is there a way to make this script more effective?

Okay so. I have been working on a admin software, which uses custom accounts to access databases and manage these.
When a player logs into a database account, the system needs to fetch all the databases this account is a member of. I wrote a little script to do that, but it literally takes 38 seconds, just to go trough all this and register one database in the UI. Is there any way to make it more efficent / quicker?

The code:

for i = 1, #boards do
			for i = 1, #DBInfo do
				local exact = DBInfo[i]:split(",")
				if boards[i] == exact[1] then
					local Accounts = API:GetListID("Accounts", exact[2])
					local Accounts1 = API:GetCardsInList(Accounts)
					for i = 1, #Accounts1 do
						if Accounts1[i].name == then
							rankinfo = Accounts1[i].desc
					local Classlist = API:GetListID("Classes", exact[2])
					local Classes = API:GetCardsInList(Classlist)
					for i = 1, #Classes do
						local rankid = Classes[i].desc:split("|")
						if rankinfo == rankid[1] then
							local DBSetList = API:GetListID("DBSettings", exact[2])
							local DBSettings = API:GetCardsInList(DBSetList)
							local DBSetCard = DBSettings[1]
							local DBSetDesc = DBSetCard.desc:split("|")
							local DBIcon = DBSetDesc[2]
							local rank = Classes[i].name
							local DBName = DBSetDesc[3]
							if lastrun ~= DBName then
								local rdata = {}
								rdata[1] = DBName
								rdata[2] = DBIcon
								rdata[3] = rank
								local response = "createdbcard"
								event2:FireClient(player, response, rdata)
								lastrun = DBName
1 Like

I’m not sure if the scripting itself can be optimized, but I think you might want to rethink your networking/processing.

Perhaps of loading all the databases’ content onto the admin’s client (which probably takes up those 38 seconds you mention), wouldn’t it be better to have the client send requests to the server to perform administrator actions (and manipulate data) there?
And if you need e.g. player data to be displayed to the admin, consider the option to send an identifier (userId) to the server, to which the server replies with the correct player data.
(Even if these databases contain something other than user-info, the same concept would still work.)

If for some reason you do need a whole database on the admin’s client, you can consider only loading in a single one at a time, when it’s requested.

1 Like

It’s not even loading all the databases content, but rather just requesting name, the users access level and a picture.
There you can see what it actually loads:

The problem is just that I shoved 5 for loops into each other and Lua doesnt like that / it takes time