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

TweenPosition isn't working when a TextButton is clicked?

Ok, so I was trying to make it so when you click the button, the frame comes out of the screen smoothly by using TweenPosition.

It somehow shows an error in this simple script.

local mainround = script.Parent.Parent.Parent.Parent.MainRoundify

script.Parent.MouseButton1Click:Connect(function()
	mainround:TweenPosition(
	UDim2.new(-3.5, 0,0.605, 0),
	1,
	"In",
	"Quad",
	false

)
end)

Where is the script located at?

The script is located in the StarterGui inside of a Round frame

What type of script?

It is a server script, the normal script we use.

The error it shows on the output says:

Unable to cast string to token

The erroring line is Line: 4

What did you do to try and fix it?

I tried removing the other script that was inside the TextButton, tried putting it in a local script rather than a server script. I removed some code lines that was inside the script and those were:

local function ShowGui()
mainround:TweenPosition(
	uDim2.new(0.501, 0,0.605, 0),
	1,
	"In",
	"Quad",
	false
)
end

Thanks so much if you answered, I'm fully patient.

2 comments

0

Try replacing 'In' and 'Quad' with: Enum.EasingDirection.In and Enum.EasingStyle.Quad

0

Also, use a LocalScript

2 answers

✓ Accepted answer

Hello there.

Alright so there are a few errors in your script.

.1 You dont use scripts for Client side, instead use local scripts.

.2 Your setting the time first, and thats wrong, do this instead:

mainround:TweenPosition(UDim2.new(-3.5, 0,0.605, 0), "In", "Quad", 1, false)

Always follow this style for UDim2 Tweens: https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition

Also, you could use UDim2.fromScale(scaleX, scaleY) instead of what your doing. Please vote this if it helped you.

6 comments

0

This worked thank you so much :D

0

local scripts are client sided, he set the position first.

0

No problem Zombie, if you could mark this as the answer i would be glad

0

I don't think I have enough reputation to upvote you, because i'm new to this website.

0

Or is it not necessary and I don't know how to mark it as answer?

0

You can mark anything as answered no matter how much rep you have

There are a few issues I can see here.

Firstly, you need to use a LocalScript for tweening.

Secondly, you are receiving this error because your arguments are mismatched!

The correct order is: Direction, Style, Time, True/False

Here is your fixed code!

local function ShowGui()
	mainround:TweenPosition(
		UDim2.new(0.501, 0,0.605, 0),
		'In',
		'Quad',
		1,
		false)
end

I also tried this out with a script of my own, here is the code for that!

local tween = 1

script.Parent.MouseButton1Click:Connect(function()
	if tween == 1 then
		script.Parent:TweenPosition(UDim2.new(0,1042,0,170), "In", "Linear", 1)
		tween = 2
	elseif tween == 2 then
		script.Parent:TweenPosition(UDim2.new(0,328,0,698), "In", "Linear", 1)
		tween = 1
	end
end)

If you have further questions, you can ask me or check out the official DevForum post.

1 comment

1

Thanks, this had more information and I now know the correct order for Tweening GUI's :D

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