A Question asked by a rookie

is there a way for me to turn for every item in the table

tableexample = {
    tblex1 = "rbxassetid://123",
    tblex2 = "rbxassetid://456",
    tblex3 = "rbxassetid://789",
}
--not my actual script cus im still brainstorming how it would look like

into a instance button that can be compatible with “:Connect(function()” ?
im sorry if it sounds like a bunch’o gargle im very new to scripting :sweat:

Yes it is possible using a for loop

2 Likes
for _, id in arrayOfIds do
    local button = Instance.new("ImageButton")
    button.Image = id
    -- set position, size, and parent to whatever you want
    button.Activated:Connect(function()
        -- button gets clicked
    end)
end
2 Likes

Yes, you can loop the table and create instances using it.

Example code:

local tableexample = {
	tblex1 = "rbxassetid://123",
	tblex2 = "rbxassetid://456",
	tblex3 = "rbxassetid://789",
}

local function CreateButton(imageId)
	local newButton = Instance.new("ImageButton")
	newButton.Image = imageId
	newButton.Parent = script.Parent
	
	newButton.MouseButton1Down:Connect(function()
		print("MouseDown")
	end)
end

for i, imageId in pairs(tableexample) do
	CreateButton(imageId)
end
3 Likes

thanks it works!

i was struggling for like 1-2 hours searching in yt about this question i did
glad i asked in the forum and you gave me a answer
thank you again

3 Likes

No problem. If you have any more questions, feel free to ask.

3 Likes

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