Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with TweenPosition?

I'm trying to understand TweenPosition, so I made a GUI, inserted a frame, and added this script into the textbutton of the frame.

local Button = script.Parent
Frame = script.Parent.Parent

Button.MouseButton1Click:connect(function(close)
	if Frame.Visible == true then
		Frame.TweenPosition = UDim2.new(0,100,0,300)
	end
end)

When I tried to execute it, the output tells me that TweenPosition isn't a valid member of the frame, could anyone explain to me what I'm doing wrong?

1 answer

✓ Accepted answer

TweenPosition is a function of GuiObject, not a property. Functions are executed like so:

Frame:FUNCTIONNAME(Parameters)

Also, you need to make sure to include all necessary parameters! Please reference the wiki.

local Button = script.Parent
Frame = script.Parent.Parent

Button.MouseButton1Click:connect(function(close)
    if Frame.Visible == true then
        Frame:TweenPosition(UDim2.new(0,100,0,300),"Out", "Quad", 1, true)
    end
end)

Edit "Quad" is the EasingStyle. The EasingStyle controls how fast it goes at any given point. The EasingStyle Linear makes it go the same pace the whole time, Sine starts fast and slows the closer it gets to the destination. Here are a bunch of graphs showing the equations for each combination of EasingStyle and "In", "Out", or "InOut".

The 1 is the float time, or in other words the amount of time it takes to Tween the object.

The last boolean at the end is for whether or not this tween can be interrupted by another Tween. Right now it is at true, so you could start another Tween on this frame and it would override the current one being run. If it was false, the new Tween wouldn't run.

3 comments

0

Thank you, I referred to the Wiki after I posted this, and I was hoping for an explanation, but what you've given me is alright, I've figured it out now. Thank you for your time.

0

If you have any questions about TweenPosition, I can answer them.

0

There was one thing I couldn't find on the wiki, but why do you add "Quad, "1", true at the end?

This discussion is preserved as it was. New answers, comments, and votes are closed.