Frame not going down

Hey there! I’m creating a draggable frame for my admin system and when I press X it doesn’t go down (like it’s supposed to), it goes to the side.

What it’s doing:

My code:

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Parent:TweenPosition(UDim2.new(0, script.Parent.Parent.Parent.AbsolutePosition.X, 1, 0), "Out", "Quad", .3)
	
	wait(.3)
	
	script.Parent.Parent.Parent.Visible = false
end)

Any help will be appreciated, as I have no idea what’s going on.

1 Like

Check the X Offset value and your AnchorPoint.

Typically, you want to set the AnchorPoint to the exact center (.5, .5) when the GUI is going to be at the center of the screen. Then, the position would also use 0.5 for the scaling, e.g. UDim2.new(.5, 0, .5, 0).
In your case, when the GUI needs to disappear by going straight down, the AnchorPoint should be .5, 0 and the position to tween to should be UDim2.new(.5, 0, 1, 0).

1 Like

I’m trying to make it go down based on the current x coordinates. This is so it looks smooth & goes directly down.

Great! So do what he said, it will work.

I think he wanted to make when X keybind button pressed, the frame tweens

local button = script.Parent
local frame = script:FindFirstAncestorWhichIsA("Frame")

button.MouseButton1Click:Connect(function()
	frame:TweenPosition(UDim2.new(frame.Position.X.Scale + frame.Size.X.Scale/2, 0, 1, 0), "Out", "Quad", .3)
	task.wait(.3)
	frame.Visible = false
end)

I assume you want the Frame instance to slide down the screen until it disappears, if so the above will work. Remember to use task.wait() instead of wait() as it’s more accurate.

This went down, but I want it to go directly down from the position of the frame.

This sounds like you want it to go down with the X value not changing. You’d just need to set the x values in the tween to be the current position values of the frame instead of in the middle of the screen.

Please correct me if I’m understanding you wrong.

How would I do this?

Nepzerox (:

I’ve modified @Forummer’s code a little. Try testing this and see if it works.

local button = script.Parent
local frame = script:FindFirstAncestorWhichIsA("Frame")

button.MouseButton1Click:Connect(function()
	frame:TweenPosition(UDim2.new(0, frame.AbsolutePosition.X, 1, 0), "Out", "Quad", .3)
	task.wait(.3)
	frame.Visible = false
end)
local button = script.Parent
local frame = script:FindFirstAncestorWhichIsA("Frame")
local framePos = nil

frame:GetPropertyChangedSignal("Position"):Connect(function()
	button.MouseButton1Click:Connect(function()
		frame:TweenPosition(UDim2.new(frame.Position.X.Scale + frame.Size.X.Scale/2, 0, 1, 0), "Out", "Quad", .3)
		task.wait(.3)
		frame.Visible = false
	end)
end)

I wasn’t aware that it was draggable, you can do the above to dynamically change the tween, according to its current position and size, which is created and then played upon the button being clicked.

I think you forgot to check for the scale/offset of the absolute position.