It works well, however I want it to go back after it completes the tween, right now it just snaps back to the start of the tween instead of going backwards
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local localPlayer = Players.LocalPlayer
local camera = workspace.CurrentCamera
local partB = workspace.Cam.B
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("Head")
local speed = 1
local distance = (partB.Position - humanoidRootPart.Position).Magnitude
local duration = distance / speed
local cameraTweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear)
local targetCFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -9 * distance)
local tween = TweenService:Create(camera, cameraTweenInfo, {CFrame = targetCFrame})
tweenBackWards = TweenService:Create(camera, cameraTweenInfo, {CFrame = targetCFrame})
local playerGui = script.Parent
local greenButton = playerGui:WaitForChild("Green"):WaitForChild("Start")
local isMovingForward = true
greenButton.Activated:Connect(function()
tween:Destroy()
tweenBackWards:Destroy()
script.Parent.Green:Destroy()
script.Parent.Background.Frame.Visible = true
script.Parent.Background.Frame.BackgroundTransparency = 0
wait(1)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
wait(.5)
script.Parent.Background.Frame.BackgroundTransparency += 0.1
greenButton:Destroy()
tween:Destroy()
tweenBackWards:Destroy()
end)
while true do
tween:Play()
tween.Completed:Wait()
tween:Cancel()
tweenBackWards:Play()
tweenBackWards.Completed:Wait()
end