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