Need help using tables in pairs loop?

How would I run this function for every given table with the corresponding variables? (Price, ID, Desc)

local SpeedCoil = {
	Price = 500,
	ID = "rbxassetid://12957402434",
	Desc = "A speed coil that harnesses raw agility into a quick dash, intended for evasive manuevers"
}
local BearTrap = {
	Price = 300,
	ID = "rbxassetid://6977364783",
	Desc = "A trap that disables The Car temporarily."
}
local BananaPeel = {
	Price = 150,
	ID = "rbxassetid://7945599806",
	Desc = "A trap that alters the steering of a driver."
}
local Caltrop_Bag = {
	Price = 400,
	ID = "rbxassetid://7844047192",
	Desc = "A trap that slows The Car temporarily, with multiple uses."
}
local Jetpack = {
	Price = 600,
	ID = "rbxassetid://447051856",
	Desc = "A utility that allows users to propel themselves high distances to evade obstacles. Do note very limited fuel due to ROBUX inflation."
}

function createInstance(ID, Price, Desc)
	local image = Instance.new("ImageButton")
	image.Image = ID

	
	image.Parent = script.Parent.List
	
	image.Activated:Connect(function()
		script.Parent.Purchase.Text = Price
		script.Parent.Notice.Text = Desc
	end)
end

for i, v  in pairs(SpeedCoil, Caltrop_Bag, Jetpack, BananaPeel) do
	createInstance(i.ID, i.Price, i.Desc)
end

You should put all of those in one table, and then do:

for i, v  in pairs(yourtable) do
	createInstance(v.ID, v.Price, v.Desc)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.