I made a script that creates 7 Text Buttons, After that tried to change his name to 7 distinguished names who are on a "Folder", but instead each have a name with them everyone is the same name, What did I do?
The Script :
for i = 1,6 do Button = script.Parent.Skills.Background.Magic.Magics:Clone() Button.Parent = script.Parent.Skills.Background.Magic Button.Position = Button.Position + UDim2.new(0,0,0,i * 31.80) end Magics = game.ReplicatedStorage.Colors:GetChildren() Buttons = script.Parent.Skills.Background.Magic:GetChildren() for i = 1,#Magics do for b = 1,#Buttons do if Buttons[b].ClassName == "TextButton" then Buttons[b].Text = Magics[i].Name end end end
Sorry is not able to understand, I'm not American then my English is bad
I am assuming you want to create a button for each thing in the "Magics" folder.
With that description, it makes sense to start with a for
loop over that folder:
for i, magic in pairs(script.Parent.Skills.Background.Magic:GetChildren()) do
We want to make a button for each, so that should be inside the for
loop:
local button = script.Parent.Skills.Background.Magic.Magics:Clone() button.Parent = script.Parent.Skills.Background.Magic button.Position = button.Position + UDim2.new(0,0,0, i * 31.80)
and each should have its text set according to the name:
button.Text = magic.Name
which is the end of the code:
end
Altogether,
for i, magic in pairs(script.Parent.Skills.Background.Magic:GetChildren()) do local button = script.Parent.Skills.Background.Magic.Magics:Clone() button.Parent = script.Parent.Skills.Background.Magic button.Position = button.Position + UDim2.new(0,0,0, i * 31.80) button.Text = magic.Name end
Don't overcomplicate.
Moving information silently between two places, as you do by putting a bunch of buttons into a folder and then later using :GetChildren()
to find them again, is a bad sign.
Instead of leaving things around to find later, just make them precisely where you need them.
Don't put a for loop inside of a for loop unless you need to do something for-each for-each.