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

Why does this camera script delete my character?

Asked by 3 years ago

I edited this script from an open-source starter place, does anyone know why when I test it my character disappears?

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

camera.CameraType = Enum.CameraType.Scriptable

local targetDistance = 10
local cameraDistance = 5
local cameraDirection = Vector3.new(-10,0,0)

local currentTarget = cameraDirection*targetDistance
local currentPosition = cameraDirection*cameraDistance

game:GetService("RunService").RenderStepped:connect(function()
    local character = player.Character
    if character and character:FindFirstChild("Humanoid") and character:FindFirstChild("HumanoidRootPart") then
        local head = character.Head
        camera.Focus = head.CFrame
        if head:FindFirstChild("FastStart") == nil then
            camera.CoordinateFrame =    CFrame.new(Vector3.new(head.Position.X, head.Position.Y + 10, head.Position.Z - 20) + currentPosition, 
                                        Vector3.new(head.Position.X,  head.Position.Y, head.Position.Z - 20) + currentTarget)
        else

            camera.CoordinateFrame = CFrame.new(Vector3.new(head.Position.X, head.Position.Y - 15, head.Position.Z - 20) + currentPosition, 
                                                Vector3.new(head.Position.X,  head.Position.Y - 15, head.Position.Z - 20) + currentTarget)
        end
    end
end)

Answer this question