I am trying to script a menu as a showcase of my skill, one of the tabs has a lot of buttons, each one looking the same and doing the same thing basically and it’s called the same, now I am trying to run a function for all of these buttons in one script so in case I need to change something I only need it to run once
here is the function
function module.buttonHover(button) -- tween button when mouse is hovering
local buttonPos = button.Position
local tweenInfo = module.getDefaultTweenInfo(0.1)
local hoverPosition = buttonPos + UDim2.new(0, 0, 0, 3)
local hoverTween = tweenService:Create(button, tweenInfo, {Position = hoverPosition})
local backTween = tweenService:Create(button, tweenInfo, {Position = buttonPos})
button.MouseEnter:Connect(function()
hoverTween:Play()
end)
button.MouseLeave:Connect(function()
backTween:Play()
end)
end
and here’s the local script
local mainFrame = script.Parent.mainFrame
local buttons = mainFrame.Buttons
for _, child in pairs(mainFrame:GetChildren()) do
if child.Name == "inventoryFrame" then
ModFunctions.buttonHover(child)
end
end
I am not getting any errors and when I use the function outside of the for loop it works but only for one of the buttons