Hello! I’ve recently made a 3rd person over the shoulder camera, but I’ve noticed an issue. After the player dies the camera does not reattach to them. It’s probably something simple, but I can’t think of a solution as I’m new to camera scripting.
I’ve tried no solutions as I’m quite new to camera scripting and can’t think of a solution.
Script:
local player = game.Players.LocalPlayer
local playButton = player.PlayerGui:WaitForChild("Main menu").Frame.PlayButton
local camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local default = UserSettings().GameSettings
local runService = game:GetService("RunService")
local offset = 2.5
local mouse = player:GetMouse()
local CAS = game:GetService("ContextActionService")
local swapkey = Enum.KeyCode.V
local cameraOffset = Vector3.new(2,2,8)
local acameraOffset = Vector3.new(-2,2,8)
playButton.MouseButton1Click:Connect(function()
--player.CharacterAdded:Connect(function(character)
local char = player.Character or player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local cameraAngleX = 0
local cameraAngleY = 0
local function playerInput(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Change then
cameraAngleX -= inputObject.Delta.X
cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 37)
end
end
CAS:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
runService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
local startCFrame = CFrame.new(hrp.CFrame.Position) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY),0,0)
local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraOffset.X, cameraOffset.Y, -1000000))
local acameraCFrame = startCFrame:PointToWorldSpace(acameraOffset)
local acameraFocus = startCFrame:PointToWorldSpace(Vector3.new(acameraOffset.X, acameraOffset.Y, -1000000))
local function onInput(input)
if input.KeyCode == swapkey then
camera.CFrame = CFrame.lookAt(acameraCFrame, acameraFocus)
else
camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)
end
end
camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)
end)
end)
local function focusControl(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
camera.CameraType = Enum.CameraType.Scriptable
CAS:UnbindAction("FocusControl")
end
end
CAS:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus )
As I’m writing this I’m thinking it’s probably due to requiring the GUI to be pressed to first lock the camera? I’m guessing an or statement is probably what I need, and it runs on player death?