How To Tween any gui?

Hello, I’m working on a project which requires the use of tweening. I have watched many tutorials on TweenService and read up on some materials such as:

https://developer.roblox.com/en-us/api-reference/class/TweenService

and

However I still am having some confusions. The confusions are mostly related to how to do certain types of tweening. I have noticed the articles show tweens of positions, colors, parts, etc… Which makes it hard to learn.

Im trying to Tween a gui using advanced options.

  1. I’m trying to make it so that it tweens at the same SPEED as if the part was close or super far.

for example a tween would make the gui tween slow for something really far away but fast for something close. I want this to be the same speed but I find it complex to find the resources for this.

  1. I’m trying to make a tween right after the initial tween without it getting mixed up by lag etc. I have seen stuff like Tween.Compled:Wait() or something but like i said resources get confusing.

So far what i think i do to tween a gui is

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(1) 
local Position = Udim2.new(0.5,0,0.5,0)
-- i want it the same speed no matter how far it is or close
local PlayThis = TweenService:Create(Script.Parent, TweenInfo, Position)
1 Like

the “speed” is the first paramater of the TweenInfo.new() did u mean something else?

u dont write correctl the udim2 try like this:

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(1) 
local Position = UDim2.new(0.5,0,0.5,0)
-- i want it the same speed no matter how far it is or close
local PlayThis = TweenService:Create(Script.Parent, TweenInfo, Position)

how do i make the speed the same no matter how far or how close the position it’s tweening is?

also i wrote the code in the forum not in studios. If i was in studios i wouldnt do that incorrectly it was just an example for my issue

im tired rn‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎

3 Likes

So you’re unable to tell me how? Do i have to make some complex math script that calculates the amount of seconds i put or something? Are you sure there’s nothing built in.

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(1) 
local Position = {UDim2.new(0.5,0,0.5,0)}
-- i want it the same speed no matter how far it is or close
local PlayThis = TweenService:Create(Script.Parent, TweenInfo, Position)

u forgot the brackets ‎ ‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‏‏‎

brackets are not required, as of Lua 5.4.4

(oh wait they might be for the TweenService)

How do i make the tween play as fast as it would play for an object close or far away? It speeds up when something is close and slows down when something is far

yeah‎ its part of TS‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎

How do i make the tween play as fast as it would play for an object close or far away? It speeds up when something is close and slows down when something is far

uh maybe u should use some math‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎‎ ‏‏‎

Hey for some reason I’m getting the error entitled:

Unable to cast to Dictionary  -  Client - LocalScript:177

the script is

local Position = UDim2.new(0.725, 0,0.753, 0)
local tweenservice = game:GetService("TweenService")
local Info = TweenInfo.new(2)

local PlayThis = tweenservice:Create(Box,Info,{Position}) -- ERROR HERE
PlayThis:Play()
PlayThis.Completed:Wait()

You can use GuiObject:TweenPosition,

local endPosition = UDim2.new(0.725, 0,0.753, 0)

script.Parent:TweenPosition(endPosition)

This is true but it is not good for what I’m trying to do and It’s very bad practice to use. I need to learn how to actually tween and not use noob functions. It’s lazy and embarrassing to use if other scripters or even hackers view your code and will give extreme bad rep. It basically tells anyone who understands code that you don’t understand code.

is more optimizated whe u use guiobject:tweenposition() than use tween service and also reduce code lines so…

It’s a supported function, it behaves exactly like normal tweening and it doesn’t show that you “don’t understand code”. I still use it in new projects because its quick and easy, much easier than calling tween service.

Anyways, here is a hopefully working script.

local tweenService = game:GetService("TweenService")
local Info = TweenInfo.new(1)

local PlayThis = tweenService:Create(Path.To.Ui.Object,Info,{ Position = UDim2.new(New.Position.Here) })
PlayThis:Play()
PlayThis.Completed:Wait()

the Udim2 is a variable named position

Okay, so change the UDim2 to the position variable.

How do i make it so that the tween is always the same speed no matter how far the gui is?