Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I Can not Rename each Button in Game ?

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

11 comments

0

If you insert " if b == i then " after line 12 ? Or maybe vice-versa ?

0

Worked , Thx Guy

0

Repaired, but there is a new bug :C , But anyway, thank you

1

Why is it that people ignore England when talking about English? xd

0

Well the translator only has translation into North American English, I can not do anything. :P

0

I'm confused, what is this code even supposed to be doing?

0

read the question, not negative mark so why not read the question

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"""

0

but it has already been answered, why you come here criticizes?

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?

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

1 answer

✓ Accepted answer

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.

2 comments

0

This question has already been answered ¬¬

0

The answer in the comments is wrong. It works, but the code is a mess when it doesn't need to be.

This discussion is preserved as it was. New answers, comments, and votes are closed.