As you can infer from the title, I’m struggling to tween a model - a piston - that is set on an angle (-15). I need it to go up and down from its original position. However, my current script makes the object itself move across the workspace (another variation of the script makes it rotate oddly). See the script below for critique:
local TweenService = game:GetService("TweenService")
local PistonModel = script.Parent
local PistonPrimaryPart = PistonModel.Main
local TweenInfo = TweenInfo.new(
0.33,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
-1,
true
)
TweenService:Create(PistonPrimaryPart, TweenInfo, {CFrame = CFrame.new(234.987, 19.347, 0)}):Play()
Do you want to tween a piston model to move up and down in a straight line? If so, here:
local TweenService = game:GetService("TweenService")
local PistonModel = script.Parent
local PistonPrimaryPart = PistonModel.Main
local initialPosition = PistonPrimaryPart.Position
local targetPosition = initialPosition + Vector3.new(0, -0.435, 0) -- Adjust the Y value as needed
local TweenInfo = TweenInfo.new(
0.33,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
-1,
true
)
local tween = TweenService:Create(PistonPrimaryPart, TweenInfo, {Position = targetPosition})
tween:Play()
-- To make it move up and down continuously, you can set up a completed event.
tween.Completed:Connect(function()
PistonPrimaryPart.Position = initialPosition -- Reset the position
tween:Play() -- Restart the tween
end)
I’ve changed the script, as you recommended, and it works sufficiently. However, it does seem to wobble a bit on the x-axis. I’ve altered the x value (to mitigate this as much as possible), which you can see in the script below. Is it possible to make the tween smoother?
local TweenService = game:GetService("TweenService")
local PistonModel = script.Parent
local PistonPrimaryPart = PistonModel.Main
local StartingPosition = PistonPrimaryPart.Position
local EndPosition = StartingPosition + Vector3.new(0.1, -0.435, 0)
local TweenInfo = TweenInfo.new(
0.33,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
-1,
true
)
local tween = TweenService:Create(PistonPrimaryPart, TweenInfo, {Position = EndPosition})
tween:Play()
tween.Completed:Connect(function()
PistonPrimaryPart.Position = StartingPosition
tween:Play()
end)
Sure! Right now I’m starting my commision but I will help you later in the day. I do see it tilting a little bit, and I’ll try to get back to you as soon as possible.
I’ll apply the script to the other pistons, considering pistons work independently and out-of-sequence with each other.
I’ve noticed no change with the script you provided me. That’s ok. I’ve adjusted the tween speed to reflect how they move in real life, so the swaying is barely noticeable.