Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How would i use buttons created in a for loop?

Asked by 12 days ago

here is the script i am working with

local teamService = game:GetService("Teams")

local teamsTabel = {
    "Mailman",
    "Chef",
    "GameDev",
    "Jobless",
    "Child",    
    "Store Clerk"
}

for i, v in pairs(teamsTabel) do
    local newTeam = Instance.new("Team")
    newTeam.TeamColor = BrickColor.new(i + 20)
    newTeam.Name = v
    newTeam.Parent = game.Teams

    local newButton = game.ReplicatedStorage.Frame:Clone()
    newButton.TextButton.Text = v
    newButton.Parent = game.StarterGui.ScreenGui.Frame
end

as you can see i create a button for every job in my table, how would i go about making it so that whenever i pressed the button that was created, it can do something related to the button (eg. put me on a team same as it's index)

0
You can connect the button you make inside the loop as well thebayou 441 — 12d

1 answer

Log in to vote
0
Answered by
Qub_lex 159
12 days ago

It's possible to put the code inside the for loop, too:

for i,v in pairs(teams) do
    v.MouseButton1Down:Connect(function()
        --code
    end)
end
Ad

Answer this question