Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix Camera Interpolate that is stuck on the same part?

Asked by
ae_su -5
4 years ago

Hello everyone,

I have this problem that I been struggling off, and It's camera interpolation.

How script works: The camera follows the part using while loop.

LeftBracket - Enable Follow Camera [Working Fine]

RightBracket - Disable Follow Camera [Working Fine]

The problem is whenever the part is destroyed and I spawned a NEW part the camera is stuck on the same CFrame

Here is the LocalScript Code:

wait(2)
-- print("Script is running")

-- Variables
local Camera = workspace.CurrentCamera

local FocusPart = workspace:WaitForChild("Handball")
local EndPart = workspace:WaitForChild("EndPart")
local UIS = game:GetService("UserInputService")
local FOV = Camera.FieldOfView

_G.Enabled = false

UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.LeftBracket then
        _G.Enabled = true
        while _G.Enabled == true do
            wait()
            FOV = 30
            Camera.CameraType = "Scriptable"
            Camera:Interpolate(EndPart.CFrame, FocusPart.CFrame, 2)
        end
    end
end)

UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.RightBracket then
        _G.Enabled = false
        wait(1)
        FOV = 70
        Camera.CameraType = "Custom"
        Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Try using:

-- print("Script is running")

-- Variables
local Camera = workspace.CurrentCamera

local FocusPart = workspace:WaitForChild("Handball")
local UIS = game:GetService("UserInputService")
local FOV = Camera.FieldOfView

_G.Enabled = false

UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.LeftBracket then
        _G.Enabled = true
        while _G.Enabled do
            wait()
            FOV = 30
            Camera.CameraType = "Scriptable"
            Camera:Interpolate(workspace:WaitForChild("EndPart"), FocusPart.CFrame, 2)
        end
    end
end)

UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.RightBracket then
        _G.Enabled = false
        wait(1)
        FOV = 70
        Camera.CameraType = "Custom"
        Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    end
end)

It waits for a new "EndPart" each time.

Also why are you using _G

0
tbh I don't even know why I used _G for my Enabled, lol ae_su -5 — 4y
0
Edit: Didn't seem to work ae_su -5 — 4y
Ad

Answer this question