Is there a way to use for i,v in pairs for two instances at the same time?

Hey! im making a custom admin panel for my game and im making a cosmetic function that changes the colors of all items in the player’s backpack and character

And it would be a lot more optimized if i could handle two instance at one for i,v in pairs due to a huge amount of tools that i have

Can i do that?

1 Like

Simultaneously two “for i, v”?

1 Like

try using coroutine.wrap(function()

2 Likes

Oh ok thanks!

[characterlimit]

1 Like
local function getAllTools(player)
	local character = player.Character
	local backpack = player.Backpack
	local tools = {}
	local equippedTool = character:FindFirstChildOfClass("Tool")
	if equippedTool then
		table.insert(tools, equippedTool)
	end
	
	for _, tool in ipairs(backpack:GetChildren()) do
		if tool:IsA("Tool") then
			table.insert(tools, equippedTool)
		end
	end
	
	return tools
end

local allTools = getAllTools(player) --Requires player instance argument.
for _, tool in ipairs(allTools) do
	task.spawn(function()
		--Do stuff with each tool here.
	end)
end

You’d want to build an array of all of the player’s current tools, then you can iterate over that array and for each tool create an additional thread of execution such that everything is handled synchronously (at the same time).