Tweening A Part To Resize Forwards

Im simply trying to tween a part’s size in its forward direction, the way i’ve tried to do this is to also tween the parts position forwards

But anything i’ve tried has either resulted in breaking the entire script or moving the part in the world’s X position

function FireLazer()
	local clone = lazer:Clone()
	clone.Parent = workspace
	game:GetService("Debris"):AddItem(clone, 1)
	clone.CFrame = myRoot:FindFirstChild("LazerPart").CFrame
	
	local tweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
	local goal = {Size = Vector3.new(50, clone.Size.Y, clone.Size.Z), Position = Vector3.new(clone.CFrame.X + 25, clone.CFrame.Y, clone.CFrame.Z)}
	local tween = tweenService:Create(clone, tweenInfo, goal)
	myRoot.Anchored = true

	tween:Play()
	tween.Completed:Wait(1)
	myRoot.Anchored = false
end
2 Likes

What are the type of errors you are receiving?
I haven’t tested it, but what happens when you replace clone.CFrame.X with Position.X?

thats weird, i think your code should work. Maybe its the laser object itself
anyway heres code i made that should work

local part = script.Parent 

local originSize = part.Size
local originPos = part.Position
local deltaSize = Vector3.new(0,0,5)
local deltaPos = Vector3.new(0,0,10)

local info = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,-1,true,0)
local goals = {Size = originSize + sizeChange, Position = originPosition + sizeChange/2 + positionChange}
local myTween = game:GetService("TweenService"):Create(part, tweenInfo, tweenGoal)

myTween:Play()

PS. its moving on video because i assume you wanna make the laser move. if you dont, set deltaPos to zero. the 1-sided growth is already pre-calculated for in tweengoals

Position.X does the same output as CFrame.X from what i’ve tried

Your code has the same problems i had before, it always sizes and moves towards the world’s x position and not forwards the part

I want to resize the object to any direction the part is facing depending on its rotation

Is welding an invisible part a viable solution? Whenever the part moves, it will move accordingly. It’s kind of cheap but I don’t see why it can’t work.
If this isn’t viable, I can go find where I’ve done something similar.

I’ve found out how to do this myself by adding this into my script and was surprised to see it work

spawn(function()
		repeat wait(.01)
			clone.CFrame = clone.CFrame * CFrame.new(Vector3.new(1,0,0))		
		until tween.PlaybackState == Enum.PlaybackState.Completed
	end)

Though theres probably a way better built in tween function for this

1 Like

oh sorry.
to make the tween relative, you have to use Position = CFrame:PointToWorldSpace(deltaSize/2 + deltaPos) as this creates your vector relative to the objects CFrame.

local part = script.Parent 

local originSize = part.Size
local originCFrame = part.CFrame
local deltaSize = Vector3.new(0,0,5)
local deltaPos = Vector3.new()

local info = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,-1,true,0)
local goals = {Size = originSize + deltaSize, Position = originCFrame:PointToWorldSpace(deltaSize/2 + deltaPos)}
local myTween = game:GetService("TweenService"):Create(part, info, goals)

myTween:Play()

2 Likes

Currently, you’re tweening the “Position” property of the part which describes its position relative to the world space by translating it 25 studs along the X-axis, this translation occurs respective to the world space as orientation of the part isn’t being accounted for. To tween the part’s position relative to its current orientation in the world space then you’ll need to tween its “CFrame” property instead as it holds both positional and orientational data pertaining to the part relative to the world space. To translate the part 25 studs along the X-axis simply multiply (since we’re working with scalars, when multiplying scalars the values are essentially added) its “CFrame” property by a constructed CFrame value using the CFrame class constructor function (CFrame.new()) which just holds this 25 stud X-axis offset.

local goal = {Size = clone.Size + Vector3.new(50, 0, 0), CFrame = clone.CFrame * CFrame.new(25, 0, 0)}
3 Likes