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

My camera pan script doesn't work anymore after the update, what do I do to fix it?

Asked by 6 years ago
Edited 6 years ago

It worked fine before the update, but now it doesn't work. What do I do to fix it? Before the update it would pan to each of my set locations and rotate the camera as well, but now the camera gets stuck and doesn't move, it only just rotates.

local CameraPanMode = true

local CameraCFrameValues = {}

wait(.1)
for x, item in ipairs(script:WaitForChild("CameraPositions"):GetChildren()) do
    CameraCFrameValues[x] = item.Value
end

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
    CameraPanMode = false
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)


local SkipGui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
local SkipButton = Instance.new("ImageButton", SkipGui)
SkipButton.Size = UDim2.new(0, 190, 0, 49)
SkipButton.Position = UDim2.new(1, 0, .9, 0)
SkipButton.Image = "rbxassetid://1283904632"
SkipButton.ImageColor3 = Color3.new(0, 0, .7)
SkipButton.BackgroundTransparency = 1
SkipButton.ScaleType = Enum.ScaleType.Slice
SkipButton.SliceCenter = Rect.new(22, 22, 234, 234)
SkipButton:TweenPosition(UDim2.new(1, -158, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)

local SkipButtonTextLabel = Instance.new("TextLabel", SkipButton)
SkipButtonTextLabel.Text = "Skip Pan"
SkipButtonTextLabel.Size = UDim2.new(1, 0, 1, 0)
SkipButtonTextLabel.TextColor3 = Color3.new(1, 1, 1)
SkipButtonTextLabel.TextSize = 30
SkipButtonTextLabel.Font = Enum.Font.SourceSansBold
SkipButtonTextLabel.BackgroundTransparency = 1

local SkippedPan = false

SkipButton.MouseButton1Click:Connect(function()
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
    SkippedPan = true
    SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
    ShowGuisAgain()
end)

script.SkipPan.Event:Connect(function()
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
    SkippedPan = true
    SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
    ShowGuisAgain()
end)

local PriorGuiVisiblity = {}
local HideGuisConnection
spawn(function()
    for key, value in ipairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
        if value ~= SkipGui and value.Name ~= "LoadingGui" then
            if value:IsA("ScreenGui") then
                PriorGuiVisiblity[value] = value.Enabled
                value.Enabled = false
            end
        end
    end

    HideGuisConnection = game.Players.LocalPlayer.PlayerGui.ChildAdded:Connect(function(item)
        if item:IsA("ScreenGui") then
            PriorGuiVisiblity[item] = item.Enabled
            item.Enabled = false
        end
    end)
end)

function ShowGuisAgain()
    HideGuisConnection:Disconnect()
    for key, value in pairs(PriorGuiVisiblity) do
        if value then
            key.Enabled = value
        end
    end
end

game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = CameraCFrameValues[1]
for x = 2, #CameraCFrameValues do
    if SkippedPan then
        break
    end
    game.Workspace.CurrentCamera:Interpolate(CameraCFrameValues[x], CameraCFrameValues[x] * CFrame.new(2, 2, -10), 4)
    wait(4)
end

if not SkippedPan then
    wait(5)
end

ShowGuisAgain()

game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
CameraPanMode = false
SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
wait(1)
SkipGui:Destroy()
0
what do you mean "it doesn't work". You need to be more descriptive about your issue. I suggest you add function calls to print in the functions, and if they print, the code is executing. User#19524 175 — 6y
0
Before the update it would pan to each of my set locations and rotate the camera as well, but now the camera gets stuck and doesn't move, it only just rotates. MatthewCenance 35 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I found the solution. Camera:Interpolate is not reliable. I had to use the TweenService's TweenService:Create function to tween the camera and do the camera pan. This is what the final script ended up looking like.

local CameraPanMode = true

local CameraCFrameValues = {}

wait(.1)
for x, item in ipairs(script:WaitForChild("CameraPositions"):GetChildren()) do
    CameraCFrameValues[x] = item.Value
end

--local LastPosition = game.Players.LocalPlayer.Character.PrimaryPart.Position

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
    CameraPanMode = false
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)

--[[spawn(function()
    while CameraPanMode do
        wait(.25)
        if math.abs((game.Players.LocalPlayer.Character.PrimaryPart.Position - LastPosition).Magnitude) > 4 then
            game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
        end
    end 
end)]]

local SkipGui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
local SkipButton = Instance.new("ImageButton", SkipGui)
SkipButton.Size = UDim2.new(0, 190, 0, 49)
SkipButton.Position = UDim2.new(1, 0, .9, 0)
SkipButton.Image = "rbxassetid://1283904632"
SkipButton.ImageColor3 = Color3.new(0, 0, .7)
SkipButton.BackgroundTransparency = 1
SkipButton.ScaleType = Enum.ScaleType.Slice
SkipButton.SliceCenter = Rect.new(22, 22, 234, 234)
SkipButton:TweenPosition(UDim2.new(1, -158, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)

local SkipButtonTextLabel = Instance.new("TextLabel", SkipButton)
SkipButtonTextLabel.Text = "Skip Pan"
SkipButtonTextLabel.Size = UDim2.new(1, 0, 1, 0)
SkipButtonTextLabel.TextColor3 = Color3.new(1, 1, 1)
SkipButtonTextLabel.TextSize = 30
SkipButtonTextLabel.Font = Enum.Font.SourceSansBold
SkipButtonTextLabel.BackgroundTransparency = 1

local SkippedPan = false

SkipButton.MouseButton1Click:Connect(function()
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
    SkippedPan = true
    SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
    ShowGuisAgain()
end)

script.SkipPan.Event:Connect(function()
    game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
    SkippedPan = true
    SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
    ShowGuisAgain()
end)

local PriorGuiVisiblity = {}
local HideGuisConnection
spawn(function()
    for key, value in ipairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
        if value ~= SkipGui and value.Name ~= "LoadingGui" then
            if value:IsA("ScreenGui") then
                PriorGuiVisiblity[value] = value.Enabled
                value.Enabled = false
            end
        end
    end

    HideGuisConnection = game.Players.LocalPlayer.PlayerGui.ChildAdded:Connect(function(item)
        if item:IsA("ScreenGui") then
            PriorGuiVisiblity[item] = item.Enabled
            item.Enabled = false
        end
    end)
end)

function ShowGuisAgain()
    HideGuisConnection:Disconnect()
    for key, value in pairs(PriorGuiVisiblity) do
        if value then
            key.Enabled = value
        end
    end
end

game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = CameraCFrameValues[1]
for x = 2, #CameraCFrameValues do
    if SkippedPan then
        break
    end
    local tween = game.TweenService:Create(
        game.Workspace.CurrentCamera,
        TweenInfo.new(4, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
        {
            CFrame = CameraCFrameValues[x],
            Focus = CameraCFrameValues[x] * CFrame.new(2, 2, -10)
        }
    )
    tween:Play()
    wait(4)
end

if not SkippedPan then
    wait(5)
end

ShowGuisAgain()

game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
CameraPanMode = false
SkipButton:TweenPosition(UDim2.new(1, 0, .9, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
wait(1)
SkipGui:Destroy()
Ad

Answer this question