Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use TweenService with the code I made?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
2
Answered by
St_vnC 330 Moderation Voter
4 years ago

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

Ad

Answer this question