How do I make a part move back and forth for a certain distance and speed?

I have a part that works as a camera for my start screen but I want it to move back an forth slowly to give some immersiveness.

3 Likes

You’d have to use tweenservice to achieve that. Try this out:

local Part = game.Workspace.Part -- Change this to your part
local TweenService = game:GetService("TweenService") 
local Pos = Vector3.new(0,5,0) -- Change this to the position you want part to move to

local Moving_Info = TweenInfo.new(
0.5, --the amount of seconds you want it to take
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
5, --The amount of time you want it to repeat
true, --Whether you want it to reverse back to the original position when it's done
0 -- how much time should delay between each repitition
)

TweenService:Create(Part, Moving_Info, {Position = Pos}):Play()
5 Likes

Is there a way to make it do that infinitely?

Also, does the part have to be unanchored?

Nope, doesn’t have to be anchored. And did you read the comments?

Just change that number to a really high number, like 999999999. You should probably do math.huge instead.

Thank you, it worked! Now I have random camera angles.

1 Like

When repeatcount is less than zero tween will loop indefinitely.

More information below.

Hi, I have another question. This works but the view doesn’t change, it’s just static at wherever the part was when the gui comes up. Is there a way for the view to move with the brick?

In the camera script, you can make a while loop that constantly sets the camera’s CFrame to the parts CFrame, like this:

while true do
wait()
camera.CFrame = Part.CFrame
end
1 Like

Should I change the part to the name of the part?

Also, it doesn’t seem to work. Is this because my camera script is a localscript?

Never mind, I got it to work. However, the camera cannot rotate after the player presses play.

1 Like