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

How can I make this part go back and forth smoothly?


local clickdetector = script.Parent:WaitForChild("ClickDetector")
clickdetector.MouseClick:Connect(function()

local TweenService = game:GetService("TweenService")

local part = workspace:WaitForChild("stop")
local part1 = workspace:WaitForChild("stop1")
local part2 = workspace:WaitForChild("stop2")
local TweenInfo = TweenInfo.new(50);

local goals = {};

goals.CFrame = part1.CFrame;

local Tween = TweenService:Create(part, TweenInfo, goals)
Tween:play()
end)
	
 

That will get the part from one brick to another, but I cant figure out how to make the brick come back and forth, and for that to happen an infinite number of times.

1 answer

This is what the TweenInfo is for :)

Configure the EasingDirection parameter to Enum.EasingDirection.InOut. Put the RepeatCount to math.huge so it repeats forever.

local TweenService = game:GetService("TweenService")
local clickdetector = script.Parent:WaitForChild("ClickDetector")
local part = workspace:WaitForChild("stop")
local part1 = workspace:WaitForChild("stop1")
local part2 = workspace:WaitForChild("stop2")
local TweenInfo = TweenInfo.new(
	50, --Duration of tween
	Enum.EasingStyle.Quad, --Style
	Enum.EasingDirection.InOut, --Direction
	math.huge, --RepeatCount
	true --Reverses(goes back to start)
)
local goals = {};
local click;
click = clickdetector.MouseClick:Connect(function()
	goals.CFrame = part1.CFrame;
	local Tween = TweenService:Create(part, TweenInfo, goals)
	Tween:play()
	click:Disconnect() --Disconnect RbxScriptSignal after clicking
end)

4 comments

0

Pay attention to the Duration of the tween.

0

Wouldn't it be better to just make the tween and continually call Tween:Play();?

0

Why do you think it would be better

0

Thx goulstem

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