Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Can I SMOOTHLY Move a Part?

Im trying to learn how I can smoothly move a part. Its like tweening, but for objects. Anyone know how I can do this?

5 comments

0

You can also use BodyPosition or RocketPropulsion

0

this doesn't explain a lot, im lost. Can you explain what i should do with the script provided?

0

can i bump?

0

can i bump?

1 answer

✓ Accepted answer

You can use TweenService to smoothly move and animate baseparts (tween is short for in-between, meaning generating intermediate frames in-between two destinations).

The TweenService instance is a class, so it is done using the GetService method.

local TweenService = game:GetService('TweenService')

You'll need to set the information of the tween first. This defines how long the animation will be, the style and direction, and whatnot. This is done using TweenInfo.new().

local info = TweenInfo.new(
	2, 						--How long the tween is played for (in seconds)
	Enum.EasingStyle.Quad	,	--The behavior of the tween
	Enum.EasingDirection.Out,	--The direction of the style
	0,						--How many times the tween will be repeated
	false,					--Will the tween play in reverse as well?
	0,						--Delay between each interpolation.
)

You can see how the easing styles act here. Easing directions (In, Out, or InOut) just refers to if the style acts in the beginning, the end, or both of the interpolation.

Next, we need to set the goal, or what properties are going to be tweened. Since this is just moving a part, all we need to do is change the CFrame.

local goal = {CFrame = CFrame.new(0,0,0)} --Set the destination for the part to move to.

Lastly, we just need to create the tween and play it!

local part = workspace.Part --The basepart that will be tweened.

local Tween = TweenService:Create(part,info,goal)

Tween:Play() --Plays the tween. You can also do :Stop() to stop the tween.

That should be it. Here's the code altogether. Hope this helps!

local TweenService = game:GetService('TweenService')
local part = workspace.Part --The basepart that will be tweened.

local info = TweenInfo.new(
	2, 						--How long the tween is played for (in seconds)
	Enum.EasingStyle.Quad	,	--The behavior of the tween
	Enum.EasingDirection.Out,	--The direction of the style
	0,						--How many times the tween will be repeated
	false,					--Will the tween play in reverse as well?
	0,						--Delay between each interpolation.
)

local goal = {CFrame = CFrame.new(0,0,0)}

local Tween = TweenService:Create(part,info,goal)
Tween:Play() 

3 comments

0

Good explained already knew it, but goood

0

Just say "nice explanation". No need to brag about your knowledge

0

Very nice answer! Thank you very much, this worked very well ;)

This discussion is preserved as it was. New answers, comments, and votes are closed.