Help with offsetting position with tween service


I’m trying to get the mesh on the left to look like the mesh on the right when clicked. For this I’m using tween service. But when the mesh is clicked it ends up doing this,

(Top part goes to 0,0.383,0 instead of offsetting the meshes initial position by that number.)
Here’s my code,

local clickDetector = workspace.Metal.ClickDetector
local TweenService = game:GetService("TweenService") 
local tweenPart = game.Workspace.Metal 

function onMouseClick()
    local info = TweenInfo.new(
        1,
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.InOut,
        0,
        false,
        0
    )

    local Goals = {
        Position = Vector3.new(script.Parent.Position + Vector3.new(0,0.383,0)),
    }

    local PartTween = TweenService:Create(tweenPart, info, Goals)
    PartTween:Play() 
end

clickDetector.MouseClick:connect(onMouseClick)

What am I doing wrong? Am I offsetting the meshes position incorrectly? And how do I fix it?

Thanks in advance.

Everything looks right, my guess would be how you wrote the position. Maybe instead of how you did it do:

Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y + 0.383, script.Parent.Position.Z)

2 Likes

This worked perfectly, thanks a ton.

1 Like