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

I Can not Rename each Button in Game ?

Asked by 8 years ago
Edited 8 years ago

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

0
If you insert " if b == i then " after line 12 ? Or maybe vice-versa ? 1N0body 206 — 8y
0
Worked , Thx Guy Rodrigo2003 76 — 8y
0
Repaired, but there is a new bug :C , But anyway, thank you Rodrigo2003 76 — 8y
1
Why is it that people ignore England when talking about English? xd TheDeadlyPanther 2460 — 8y
View all comments (7 more)
0
Well the translator only has translation into North American English, I can not do anything. :P Rodrigo2003 76 — 8y
0
I'm confused, what is this code even supposed to be doing? BlueTaslem 18071 — 8y
0
read the question, not negative mark so why not read the question Rodrigo2003 76 — 8y
0
Your question is unclear, ambiguous, and difficult to parse. Do you mean something like: """I want to make 7 buttons, eached with a label for one  object in the "Magics" folder""" BlueTaslem 18071 — 8y
0
but it has already been answered, why you come here criticizes? Rodrigo2003 76 — 8y
0
how are you able to script if you do not understand english? Is it sort of like learning two languages at once- a lingual and a programming one? Volodymyr2004 293 — 8y
0
was easy to learn what each command does that already and a new language, and I can speak English, but my vocabulary is very limited , for me write this message i used the translator to try to get a little easier to understan Rodrigo2003 76 — 8y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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.

0
This question has already been answered ¬¬ Rodrigo2003 76 — 8y
0
The answer in the comments is wrong. It works, but the code is a mess when it doesn't need to be. BlueTaslem 18071 — 8y
Ad

Answer this question