For i,v in pairs set ImageButtons problem

What do you want to achieve?
I’m making a script that sets all imagebuttons to rotate or change size so I don’t have to make them individual

What is the issue?
Only one button rotates and changes
https://gyazo.com/a5f3441601c32c106d3c55bc9e6f739a

What solutions have you tried so far?
I tried everything but it still does not work

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteFolder = ReplicatedStorage:WaitForChild("Remotes", 1)
local BindEventFolder = RemoteFolder:WaitForChild("BindEvents")

local Frame = script.Parent
local FrameOpenBE = BindEventFolder.FrameOpen

local Button 
local FrameName

for i,v in pairs(Frame:GetChildren()) do
	if v:IsA("ImageButton") then
		Button = v
		FrameName = v.FrameName
		print(v)
	end
end

Button.MouseLeave:Connect(function()
	Button.Size = UDim2.new(0.421, 0,0.265, 0)
	Button.Rotation = 0
end)

Button.MouseEnter:Connect(function()
	Button.Rotation = 5
end)

Button.MouseButton1Click:Connect(function()
	Button.Size = UDim2.new(0, 105,0, 106)
	wait(.1)
	Button.Size = UDim2.new(0.421, 0,0.265, 0)
end)

You should make all events inside the for loop.
v.MouseLeave, v.MouseEnter etc.

1 Like