for i, v in pairs(buttons) do frame[v].MouseEnter:Connect(function() sounds.Hover:Play() local position = frame[v].Position frame[v]:TweenService(Position == position + UDim2.new(0, 0, 0, -2),"Out","Quad",1) end) frame[v].MouseLeave:Connect(function() local position = frame[v].Position frame[v].Position = position + UDim2.new(0, 0, 0, -2) end) end
not works
First, TweenService is a service, not a function. So instead of using TweenService, use TweenPosition. Also TweenPosition takes a position as its first parameter, so there is no need to check anything. I also noticed that you're using mapping to find the "frame" when you already have it with v, so instead of frame[v] just write v. You should also add true as your 5th parameter to make sure that the tween can be interrupted by another tween so it doesn't break if you take the mouse off of the frame before the first tween is done. You should replace line 9 with:
v:TweenPosition(position + UDim2.new(0, 0, 0, -2), "Out", "Quad", 1, true)
do something similar with your MouseLeave event so your frame moves smoothly. Since there are a lot of problems to fix, i'll rewrite your code for you:
for i, v in pairs(buttons) do local position = v.Position -- define the position of your frame before the functions to make sure that a position isn't recorded while a tween is in progress v.MouseEnter:Connect(function() sounds.Hover:Play() v:TweenPosition(position + UDim2.new(0, 0, 0, -2), "Out", "Quad", 1, true) end) v.MouseLeave:Connect(function() v:TweenPosition(position, "Out", "Quad", 1, true) end) end
Hope this helps!