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

How do I use TweenService with the code I made?

Hello, I made this code... but there is one problem is that it looks like it is teleporting from stud to stud, and I am trying to make it's movement smoother. But however, I don't know how to do that, Here is the code I made.

while true do
 wait(3)
wait()
 for i = 1,90 do
 script.Parent.CFrame = CFrame.new(script.Parent.Position + Vector3.new(.5,0,0))
 wait()
 end
wait(3)
 for i = 1,90 do
 script.Parent.CFrame = CFrame.new(script.Parent.Position - Vector3.new(.5,0,0))
 wait()
 end
end

Also, the purpose of the script is to make the part move from location to location. If anyone can solve this problem, it would be appreciated.

1 answer

✓ Accepted answer

Try :

local TweenService = game:GetService("TweenService")
 
local part = script.Parent
 
local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
 
local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(0, 30, 0)})
 
tween:Play()
 

From the wiki

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