Some help with cloned buttons

Alrighty so I’m working on an avatar editor. Each shirt is stored in a folder here:
image
It does not matter whether all Shirts children are named the same or not, as I’ve tested changing their names aswell.

And each shirt folder has these children:
image

local ShirtTotal = 0
for i,v in pairs(game.ReplicatedStorage.Client.Shirts:GetChildren()) do
	ShirtTotal = ShirtTotal + 1
	
	imgbut  = script.Parent.ShirtSelector.ImageButton:Clone()
	imgbut.Parent = script.Parent.ShirtSelector
	
	imgbut.Visible = true
	
	imgbut.Name = "Shirt"..ShirtTotal
	imgbut.Image = "rbxassetid://"..v.ShirtDisplayId.Value
	
	imgbut.ShirtText.Value = "rbxassestid://"..v.TextureId.Value
	
	imgbut.MouseButton1Click:Connect(function()
		print(imgbut.Name)
		game.Workspace.JoinDummy.Shirt.ShirtTemplate = imgbut.ShirtText.Value
	end)
end

Things that work:

  • Naming
  • ImageButton image being set

Basically, the rest doesn’t work.
When I click imgbut, I ALWAYS get the output of Shirt3, as that is probably the most recent one cloned.

Setting the dummies shirt doesn’t work either.

Can I get some help with this? Thanks! :heart:

1 Like

this is why its a good practice to start variables off as local . the reason why it doesn’t work is the variable imgbut is being overwritten; this is the reason why you get the same output “most recent one cloned”. literally just add local to the front of imgbut

2 Likes