Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i use buttons created in a for loop?

Asked by 3 years 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 — 3y

1 answer

Log in to vote
0
Answered by
sngnn 274 Moderation Voter
3 years 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