Better way to tween?

Hello! I have this part tween. I wonder if there’s a better way to tween it or keep it like it is.

-- RunContext = Client

local ts = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 3)

local Folder = script.Parent:GetChildren()

for i, MovingPlatform in pairs(Folder) do
	if MovingPlatform:IsA("Model") or MovingPlatform:IsA("BasePart") then
	local MoveHit =	MovingPlatform:WaitForChild("MovingHit")
	local Destination = MovingPlatform:WaitForChild("Destination")

	local CF_Down = {
		CFrame = CFrame.new(Destination.CFrame.X, Destination.CFrame.Y, Destination.CFrame.Z)
		
	}
	
	local DownTween = ts:Create(MoveHit, info, CF_Down)
		DownTween:Play()
		
	end
	
end
2 Likes

You can save lines by changing this

-- RunContext = Client

local ts = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 3)

local Folder = script.Parent:GetChildren()

for i, MovingPlatform in pairs(Folder) do
	if MovingPlatform:IsA("Model") or MovingPlatform:IsA("BasePart") then
	local MoveHit =	MovingPlatform:WaitForChild("MovingHit")
	local Destination = MovingPlatform:WaitForChild("Destination")

	local CF_Down = {
		CFrame = CFrame.new(Destination.CFrame.X, Destination.CFrame.Y, Destination.CFrame.Z)
		
	}
	
	local DownTween = ts:Create(MoveHit, info, CF_Down)
		DownTween:Play()
		
	end
	
end

into this.

-- RunContext = Client
local Folder = script.Parent:GetChildren()

for i, MovingPlatform in pairs(Folder) do
	if MovingPlatform:IsA("Model") or MovingPlatform:IsA("BasePart") then
	local MoveHit =	MovingPlatform:WaitForChild("MovingHit")
	local Destination = MovingPlatform:WaitForChild("Destination")
		game:GetService("TweenService"):Create(MoveHit, TweenInfo.new(TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 3), {CFrame = CFrame.new(Destination.CFrame.X, Destination.CFrame.Y, Destination.CFrame.Z)}:Play()
	end	
end

What did I do?

  • First, I deleted TweenInfo Variable “info” and instead just added whole tweenInfo inside Tween.
  • Second, I deleted Tween Variable “CF_Down” and instead just added whole table inside Tween.
  • Third, I deleted TweenBase Variable “DownTween” and instead just made non-variable Tween play.
This line is the non-variable TweenBase ( Line 7 )

game:GetService(“TweenService”):Create(MoveHit, TweenInfo.new(TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 3), {CFrame = CFrame.new(Destination.CFrame.X, Destination.CFrame.Y, Destination.CFrame.Z)}:Play()

Hope this helped!

1 Like

I am not looking to save some lines. I am looking if there’s a more efficient way to do this.

1 Like

welp, there aren’t any more efficient ways to tween something, because you should use loops if you dont use tweens.

1 Like

Yes this shortens the lines, but it makes the code less-cleaner in my opinion by making that piece of line extremely long.

2 Likes

True, the script I did code above is very messy, it saves lines but instead makes one line of code very long which makes it hard to read.

1 Like