Camera Adjustments Stop on Player Respawn

Beginner scripter here.

I’m trying to replicate the most basic InFamous 1 mechanics as practice, currently working on the camera/aiming system; the camera is supposed to be always set to shift-lock (which I achieved through having a “FixedPlayerSettings” Script within StarterPack, which sets the CameraType to Scriptable, and a function connected to RunService.Heartbeat that keeps the MouseBehavior set to LockCenter. So far, it works.

However, if the player dies/resets, the camera gets stuck in place — it no longer follows the player/character as it should.


I assume it is because the camera is attached to the character (which I’m pretty sure is its normal behavior?), and when the character gets destroyed, the camera stays where it was. I’m positive I could fix it by only setting MouseBehavior to LockCenter after the character spawns, though I have absolutely no idea on how I should do this. As I don’t know how to fix this as of now, I’m not even moving on with the project to avoid making it a bigger issue.

Following are both the codes related to the camera:

“PlayerInput” (LocalScript within StarterCharacterScripts)

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera
local defaultFOV = 70


local UserInputService = game:GetService("UserInputService")
local isRightMouseButtonHeld = false
local boltEvent = game.ReplicatedStorage.Events.LightningBolt
local stateModule = require(game.ReplicatedStorage.Module.stateModule)
local isAiming = stateModule.isAiming 

UserInputService.MouseIconEnabled = false
local debounce = false

local function onInputBegan(input, isProcessing)
	if not isProcessing and input.UserInputType == Enum.UserInputType.MouseButton2 then
		isRightMouseButtonHeld = true
		isAiming = true
		UserInputService.MouseIconEnabled = true
		
		print("Aiming is " .. tostring(isAiming))
		camera.FieldOfView = 20
	end
end

local function onInputEnded(input, isProcessing)
	if not isProcessing and input.UserInputType == Enum.UserInputType.MouseButton2 then
		isRightMouseButtonHeld = false
		isAiming = false
		UserInputService.MouseIconEnabled = false
		
		print("Aiming is " .. tostring(isAiming))
		camera.FieldOfView = defaultFOV
	end
end

local function shootProjectile(input)
	if isAiming and input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("wahoo!!!")
		boltEvent:FireServer()
	end
end

UserInputService.InputBegan:Connect(onInputBegan)
UserInputService.InputBegan:Connect(shootProjectile)
UserInputService.InputEnded:Connect(onInputEnded)

“FixedPlayerSettings” (Script within StarterPack)

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local StarterPlayer = game:GetService("StarterPlayer")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
	if player.CharacterAdded then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	else return end
	
end)	


UserInputService.MouseIcon = "rbxassetid://15860340814"
camera.CameraType = Enum.CameraType.Scriptable
player.CameraMaxZoomDistance = 13
player.CameraMinZoomDistance = 13

Any help is appreciated! Thank you in advance.

2 Likes

Found the issue, and it was annoyingly stupid, too.

Turns out I had misunderstood what the Scriptable value for CameraType meant. Thought you would have to set the CameraType to Scriptable if you were to make any changes to how the camera worked. Simply removing the 16th line of code from the “FixedPlayerSettings” script fixed it.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.