Part Moving Smoothly between two other parts

Hello everybody! I am making a lazer light show, and I have a beam coming from a part into another part (as beams work). I would like the part to move between two parts smoothly, and obviously the beam will follow this block. This is my script:

local TweenService = game:GetService("TweenService")
local Start = game.Workspace:WaitForChild("Start")
local End = game.Workspace:WaitForChild("End")

local PartToMove = game.Workspace:WaitForChild("PartToMove")
local TweenInformation = TweenInfo.new(
	0.5, 
	Enum.EasingStyle.Linear, 
	Enum.EasingDirection.InOut, 
	5, 
	true, 
	1 
)

local EndProperties = {
	Position = End.Position	
}

local StartProperties = {
	Position = Start.Position	
}

local TweenToPlay = TweenService:Create(PartToMove,TweenInformation,EndProperties)
local StartTweenToPlay = TweenService:Create(PartToMove,TweenInformation,StartProperties)

while true do
	TweenToPlay:Play()
	wait()
end

Currently , this only goes to the part named ‘End’, but I want it to travel in between Start and End constantly. Thanks for any help!

I think there’s a property in tweens called reverse or something. Sorry, I’m not very knowledgeble at tweenservice.

Instead of using tween you can use :Lerp()

local PartToMove = game.Workspace:WaitForChild("PartToMove")
local Start = game.Workspace:WaitForChild("Start")
local End = game.Workspace:WaitForChild("End")

for i = 0,.5,.01 do
wait()
PartToMove.CFrame = start.CFrame:Lerp(End.CFrame,i)
end
-- I didnt test the code tell me if theres an errors
1 Like

No this does not work? Not sure why, but a couple of your things inside the script did not match with the references you made at the start, so I edited them?

Do you want the part to move between the 2 parts in a loop or is it something else I’m not getting?

I want the part to move betwen 2 in a loop yes

If anyone else has got any ways to fix it, if you could let me know that would be extremely helpful!

Here it is, tested and it works
If it doesn’t just @ me with the error message and I’ll have a look

3 Likes

Yeah I think that works perfectly, I’ll message you if I have any issues with it!

No problem mate, and yea I’ll be about the place if you want anything answering

1 Like