Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local localPlayer = game.Players.LocalPlayer
- local camera = workspace.CurrentCamera
- local part2D = workspace:WaitForChild("Tween1")--name of your first trigger part
- local part3D = workspace:WaitForChild("Tween2")--name of your second trigger part
- local function TweenCamera(newCFrame, newFOV)
- local tweenInfo = TweenInfo.new(
- 1,
- Enum.EasingStyle.Quad,
- Enum.EasingDirection.InOut,
- 0,
- false
- )
- local tween = game.TweenService:Create(
- camera,
- tweenInfo,
- {
- CFrame = newCFrame,
- FieldOfView = newFOV
- }
- )
- tween:Play()
- return tween
- end
- local lastCamState = nil
- local function UpdateCamera(newCamState)
- if newCamState ~= lastCamState then
- local rootPart = localPlayer.Character:FindFirstChild("HumanoidRootPart")
- if rootPart then
- if newCamState == "Tween1" then
- task.spawn(function()
- local function newCFrame()
- return CFrame.new(rootPart.Position + Vector3.zAxis * 60)
- end
- camera.CameraType = Enum.CameraType.Scriptable
- rootPart.Anchored = true
- TweenCamera(newCFrame(), 40).Completed:Wait()
- rootPart.Anchored = false
- while newCamState == lastCamState do
- camera.CFrame = newCFrame()
- task.wait()
- end
- end)
- elseif newCamState == "Tween2" or newCamState == nil then
- task.spawn(function()
- local function newCFrame()
- return CFrame.new(rootPart.Position + Vector3.zAxis * 100)
- end
- camera.CameraType = Enum.CameraType.Scriptable
- rootPart.Anchored = true
- TweenCamera(newCFrame(), 40).Completed:Wait()
- rootPart.Anchored = false
- while newCamState == lastCamState do
- camera.CFrame = newCFrame()
- task.wait()
- end
- end
- end
- lastCamState = newCamState
- end
- part2D.Touched:Connect(function(hitPart)
- local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
- if player then UpdateCamera("Tween1") end
- end)
- part3D.Touched:Connect(function(hitPart)
- local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
- if player then UpdateCamera("Tween2") end
- end)
- localPlayer.CharacterAdded:Connect(UpdateCamera)
Advertisement
Add Comment
Please, Sign In to add comment