Axolotleless

Tween

Jun 23rd, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. local localPlayer = game.Players.LocalPlayer
  2.  
  3. local camera = workspace.CurrentCamera
  4.  
  5. local part2D = workspace:WaitForChild("Tween1")--name of your first trigger part
  6. local part3D = workspace:WaitForChild("Tween2")--name of your second trigger part
  7.  
  8. local function TweenCamera(newCFrame, newFOV)
  9. local tweenInfo = TweenInfo.new(
  10. 1,
  11. Enum.EasingStyle.Quad,
  12. Enum.EasingDirection.InOut,
  13. 0,
  14. false
  15. )
  16. local tween = game.TweenService:Create(
  17. camera,
  18. tweenInfo,
  19. {
  20. CFrame = newCFrame,
  21. FieldOfView = newFOV
  22. }
  23. )
  24. tween:Play()
  25. return tween
  26. end
  27.  
  28. local lastCamState = nil
  29. local function UpdateCamera(newCamState)
  30. if newCamState ~= lastCamState then
  31. local rootPart = localPlayer.Character:FindFirstChild("HumanoidRootPart")
  32. if rootPart then
  33. if newCamState == "Tween1" then
  34. task.spawn(function()
  35. local function newCFrame()
  36. return CFrame.new(rootPart.Position + Vector3.zAxis * 60)
  37. end
  38. camera.CameraType = Enum.CameraType.Scriptable
  39. rootPart.Anchored = true
  40. TweenCamera(newCFrame(), 40).Completed:Wait()
  41. rootPart.Anchored = false
  42. while newCamState == lastCamState do
  43. camera.CFrame = newCFrame()
  44. task.wait()
  45. end
  46. end)
  47. elseif newCamState == "Tween2" or newCamState == nil then
  48. task.spawn(function()
  49. local function newCFrame()
  50. return CFrame.new(rootPart.Position + Vector3.zAxis * 100)
  51. end
  52. camera.CameraType = Enum.CameraType.Scriptable
  53. rootPart.Anchored = true
  54. TweenCamera(newCFrame(), 40).Completed:Wait()
  55. rootPart.Anchored = false
  56. while newCamState == lastCamState do
  57. camera.CFrame = newCFrame()
  58. task.wait()
  59. end
  60. end
  61. end
  62. lastCamState = newCamState
  63. end
  64.  
  65. part2D.Touched:Connect(function(hitPart)
  66. local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
  67. if player then UpdateCamera("Tween1") end
  68. end)
  69.  
  70. part3D.Touched:Connect(function(hitPart)
  71. local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
  72. if player then UpdateCamera("Tween2") end
  73. end)
  74.  
  75. localPlayer.CharacterAdded:Connect(UpdateCamera)
  76.  
Advertisement
Add Comment
Please, Sign In to add comment