How would I tween camera back to regular position?

Alright so I am working on a game. I want the camera position to tween to a part and then tween back to normal if you enter/leave a hitbox. I got it semi-working but the issue I am having right now is the camera mode (Custom) snaps back to its regular position after the tween. For those who don’t have eyes, the game isn’t first person so trying first person methods won’t work.

Here is the code;

game.Loaded:Wait(1.5)

local Toggle = false
local OriginalCamCFrame = CFrame.new(0, 0, 0)

local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')

local CamPart = workspace:WaitForChild('CamPart')
local Hitbox = workspace:WaitForChild('HitboxTeehee')

local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local BarGui = LocalPlayer.PlayerGui:WaitForChild('BarUI')

local Min = Vector3.new(Hitbox.Position.X - Hitbox.Size.X / 2, Hitbox.Position.Y - Hitbox.Size.Y / 2, Hitbox.Position.Z - Hitbox.Size.Z / 2)
local Max = Vector3.new(Hitbox.Position.X + Hitbox.Size.X / 2, Hitbox.Position.Y + Hitbox.Size.Y / 2, Hitbox.Position.Z + Hitbox.Size.Z / 2)
local Region = Region3.new(Min, Max)

while task.wait(0.15) do
	if LocalPlayer and LocalPlayer.Character and LocalPlayer.Character.Parent then
		local PartsInRegion = workspace:FindPartsInRegion3WithWhiteList(Region, LocalPlayer.Character:GetChildren())

		if #PartsInRegion > 6 then -- 5 parts to make sure char is close enough
			if BarGui.Enabled ~= true then BarGui.Enabled = true end

			if not Toggle then
				OriginalCamCFrame = workspace.CurrentCamera.CFrame
				workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
				TweenService:Create(workspace.CurrentCamera ,TweenInfo.new(0.55 , Enum.EasingStyle.Sine), {CFrame = CamPart.CFrame}):Play()
				Toggle = true
			end
		else
			if BarGui.Enabled ~= false then BarGui.Enabled = false end

			if Toggle then
				TweenService:Create(workspace.CurrentCamera ,TweenInfo.new(0.25 , Enum.EasingStyle.Sine), {CFrame = OriginalCamCFrame}):Play()
				task.spawn(function() task.wait(0.5) end)
				task.wait(0.1)
				workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
				Toggle = false
			end
		end
	end
end

2 Likes

Yeah I already tried using the code that was provided in the solution for that post. For whatever reason the code doesn’t work for me. I even changed some parts in the code with no success. I’ll try again today I guess…

Yeah I just tried it again, no luck.

Bump? having the same issue with no luck

function tween(object,array,speed,style,direction)
	style = style or Enum.EasingStyle.Linear
	direction = direction or Enum.EasingDirection.InOut
	local tweenInfo = TweenInfo.new(speed,style,direction)
	return game:GetService('TweenService'):Create(object,tweenInfo,array)
end

local part = workspace:WaitForChild('Part')
local prompt = part:WaitForChild('ProximityPrompt')

prompt.Triggered:Connect(function()
	local camera = workspace.CurrentCamera
	local originalCFrame = camera.CFrame
	camera.CameraType = Enum.CameraType.Scriptable
	local anim = tween(camera,{CFrame=part.CFrame},1)
	anim:Play()
	anim.Completed:Wait()
	anim:Destroy()
	task.wait(1)
	anim = tween(camera,{CFrame=originalCFrame},1)
	anim:Play()
	anim.Completed:Wait()
	anim:Destroy()
	camera.CameraType = Enum.CameraType.Custom
	camera,originalCFrame,anim = nil
end)

This little test works fine for me. However, it doesn’t take into account if the player moves from their original position.