Ui slider moves up when it should stay straight

this code is supposed to make my ui slider repeatedly go to the left, then right until you either cancel the swing or click mousebutton1.

all of that works fine, but I have a small problem, the slider travels to the top of the frame, instead of staying in a straight line. here is a video:
[RoTour - Roblox Studio (gyazo.com)]
(https://gyazo.com/3623b3c5841e80201c4861c363915ac7)

there’s no errors, and I thought it might be useful to say that the anchor point of the slider is 0,0.5 if that has anything to do with it.

here is the relevant code, ant there is another line of code that returns the slider to the center when you let go of the spacebar, which works fine.

local MaxLeftPos = UDim2.new(SliderUI.Slider.MaxLeft.Position.X,0,0,0)
local MaxRightPos = UDim2.new(SliderUI.Slider.MaxRight.Position.X,0,0,0)

local function SliderUpSwing()
	-- start upswing
	Slider:TweenPosition(UDim2.new(MaxLeftPos,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear,0.5,true)
	wait(0.5)
	repeat
		Slider:TweenPosition(MaxRightPos, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear,0.75)
		wait(0.75)
		Slider:TweenPosition(MaxLeftPos, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear,0.75)
		wait(0.75)
	until InSwing == false or swinging == true
end

any help is appreciated, thanks.

I’m pretty sure you’d want to put it to 0.5 in all the tween-position things since if it’s at 0,0 it’d be centered but 0.5 isn’t centered on it.

1 Like

it might be the wrong position

the anchor point?
I’ll try that.

yeah I think that’s what he meant

Either on the anchor point you should change it to 0,0 or the tweens to go down by 0.5

I am fully lazy to check the code but I think the thing that’s causing it is in line 6

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.