Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

0

tbh I don't even know why I used _G for my Enabled, lol

0

Edit: Didn't seem to work

This discussion is preserved as it was. New answers, comments, and votes are closed.