How to make part tween upwards from it's current position

As the title suggests. I want my part to go up and down FROM it’s current position in the world.

local TweenService = game:GetService("TweenService")

local part = script.Parent and script.Parent.Union

local tweenInfo = TweenInfo.new(
	3, 
	Enum.EasingStyle.Linear, 
	Enum.EasingDirection.Out,
	-1, 
	true, 
	0 
)

local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(18.15, 4.85, 91.3)})

tween:Play()

Currently the code takes the parts position and just makes it go upwards to the coordinates above it in the world.

But how do I make it so in a tween, it takes the parts current position and could just make it go up by like… 5 - 10 studs.

I believe you get the number on an axis

Example:

Vector3.new(Part.Position.X, 50, Part.Position.Z)
1 Like

The straight-forward answer is:

part.Position + Vector3.new(0, 10, 0)

It is the positive Y axis that goes upward. This is also relative to the original position.


Also it looks like Roblox’s documentation on Vector3 math is gone…

3 Likes

Not sure if this is better, but it works

However i would rather add a Vector3

2 Likes

The question implies a relative position from its current position, including its original height just in case.

1 Like

Now how do I solve the problem “Can’t cast to dictionary”

Let’s take this line.

Transform it into this:

local tween = TweenService:Create(part, tweenInfo, {Position = part.Position + Vector3.new(0, 10, 0)})

Although an alternative is to just pluck out the other vectors like previous solution:

local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(part.Position.X, part.Position.Y + 10, part.Position.Z)})
1 Like

Oh hey it works!

Thank you both of you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.