Tweening Players Position

I want to tween the character’s position to a part but the script isn’t taking them to the part. The script is below;

				local Distance = 50
				local bodyPos = Instance.new("BodyPosition")
				local targetPos = Player.Character.UpperTorso.Position
				local dragoutPos = workspace.DragTo.Position
				bodyPos.Position = CFrame.new(dragoutPos, Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)) * CFrame.new(0, 0, -Distance).p + Vector3.new(0, 5, 0)
				bodyPos.Parent = Player.Character.UpperTorso
				Debris:AddItem(bodyPos, 0.5)
1 Like

Use tween service instead of a deprecated old class. If you want to use physics though, then use AlignPosition and put an attachment in the HRP and change it to one attachment mode, make the attachment0 the attachment you put in the HRP, then put the targetPosition as the part’s position.

1 Like

I don’t really know how to do that, I’m not really experienced with that stuff.

Eh, I’m willing to teach it.

So first thing you do is get the service by going to the top of the script and writing:

TweenService = game:GetService(“TweenService”)

Now, you replace the code with the following

Info = Tween info.New(
–Your tween time in seconds–,
– Enum.EasingStyle.“whatever, test it out” –
– Enum.EasingDirection.in –
– number of times to repeat the tween (1 in your case)
– true/false to determine if the tween returns to normal
after completing the tween
– number of seconds before the tween and in between
each repetition
)

Now that the worst is ot of the way, you follow up the info with:

Tween = TweenService:Create(
– the target of the tween (the character’s
HumanoidRootPart in this case)
Info
{
–the property to tween - follow this format–
Property = final Value
–in your case that should be –
CFrame = Workspace.DragTo.CFrame
}
)

And finally:

Tween:Play()

And that is how you tween! Hope it helps!

3 Likes

Thank you! Can you make it more readable though?

1 Like

Not right now, that was all on mobile, might improve it tomorrow.

2 Likes

Ok, Here is the more readable version:
So first thing you do is get the service by going to the top of the script and writing:

TweenService = game:GetService(“TweenService”)

now, you follow up with the following code:

Info = TweenInfo.New(
    -- Time over which the tween is stretched, in seconds -- 1,
    -- The Easing Style of the tween - you can have it bounce, move at constant speed, accellerate ect. An Enum.EasingStyle -- Enum.EasingStyle.Linear
    -- The Easing Direction of a tween, an Enum.EasingDirection -- Enum.EasingDirection.In
    -- amount of times the tween gets repeated - 1
    -- whether the tween undoes itself once reaching the target, a boolean -- False
    -- amount of seconds to wait before the tween starts and inbetween tweens -- 0
)

That was the Slightly Harder part. things only get easier:
we now construct the tween with:

TweenService:Create(
    -- the target instance that performs the tween -- Character.HumaoidRootPart
    -- the Tween's Information, which we detailed above -- Info
    {-- The Properties that must be changed, which must be detailed in a table --
        -- Property to Change = target result -- CFrame = Workspace.DragTo.CFrame
    }
)

and that’s how you tween!

hope this helps

1 Like

Thank you, can I message you later to confirm if it’s correct?

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