Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

TweenPosition isn't working when a TextButton is clicked?

Asked by 2 months ago
Edited 2 months ago

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.

0
Try replacing 'In' and 'Quad' with: Enum.EasingDirection.In and Enum.EasingStyle.Quad SirGamezy 154 — 2mo
0
Also, use a LocalScript SirGamezy 154 — 2mo

2 answers

Log in to vote
0
Answered by 2 months ago

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.

0
This worked thank you so much :D ZombieApocalypz3 35 — 2mo
0
local scripts are client sided, he set the position first. greatneil80 2350 — 2mo
0
No problem Zombie, if you could mark this as the answer i would be glad CaioAlpaca 342 — 2mo
0
I don't think I have enough reputation to upvote you, because i'm new to this website. ZombieApocalypz3 35 — 2mo
View all comments (2 more)
0
Or is it not necessary and I don't know how to mark it as answer? ZombieApocalypz3 35 — 2mo
0
You can mark anything as answered no matter how much rep you have sean_thecoolman 190 — 2mo
Ad
Log in to vote
0
Answered by
skvyy 168
2 months ago

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
Thanks, this had more information and I now know the correct order for Tweening GUI's :D ZombieApocalypz3 35 — 2mo

Answer this question