All buttons take 1 text, error

	for morphName, morph in Morphs do
		for _, button in Buttons:GetChildren() do
			button.Gui.PlayerName.Text = morphName

who can help me for script please ?

for morphName, morph in Morphs do -- loop starts, lets say morphName is "Ben"
		for _, button in Buttons:GetChildren() do-- you start another loop inside the first one, morphName is still the same
			button.Gui.PlayerName.Text = morphName-- you apply it to all buttons

added comments, to help you understand what is happening, in short

button.Gui.PlayerName.Text = morphName

its not an error its just what you wrote, you loop trought all buttons and assign them same morphName as a text

but the text should be different, right?

first loop waits for second loop to end and morphName wont change until then

but how to fix this, i dont know :frowning:

local index = 0
for morphName, morph in Morphs do
index += 1
		for i, button in ipairs(Buttons:GetChildren()) 
if i == index then
			button.Gui.PlayerName.Text = morphName
end

this should do

If you are trying to get every button to show the text of a different morph, and the number of key/value pairs in the morphs table is equal to the length of the buttons table, you can do something like this:

local buttons = Buttons:GetChildren()

local i = 1
for morphName, _ in Morphs do
	buttons[i].Gui.PlayerName.Text = morphName
	i+=1
end
1 Like

This is going through every morph and setting all the buttons to the morphName. What effect are you hoping to achieve?