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

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

Asked by
Synth_o 136
6 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

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)
0
Pay attention to the Duration of the tween. Goulstem 8144 — 6y
0
Wouldn't it be better to just make the tween and continually call `Tween:Play();`? plasma_node 343 — 6y
0
Why do you think it would be better Goulstem 8144 — 6y
0
Thx goulstem Synth_o 136 — 6y
Ad

Answer this question