Own camera bug when player dies

hi, I am making my own camera for a game but I have a problem and that is that when the player just enters the game he can drag the normal camera but when the player dies it is impossible to drag the camera and I don’t know how I could fix it

everything works but when the player dies that bug appears or also when the player appears it rarely appears already with the bug done

my code here:

player.CharacterAdded:Connect(function()------------------------------------detect new character
	
	camera.CameraType = Enum.CameraType.Scriptable
	print("scriptable")
	
	----------------------------------------------------------------------------------player locals
	local char = player.Character
	local head = char:WaitForChild("Head")
	local root = char:WaitForChild("HumanoidRootPart")
	local hum = char:WaitForChild("Humanoid")
	local ChangeCamera = char:WaitForChild("CameraSystemLocal"):FindFirstChild("ChangeCamera")
	
	local x = 0
	local y = 0
	
	local function mouseMove(name, state, inputObject)
		x = x + (-inputObject.Delta.x*config.Sens/100)
		y = y + (-inputObject.Delta.y*config.Sens/100)

		if (y > config.snap) then
			y = config.snap
		elseif (y < -config.snap) then
			y = -config.snap
		end
	end

	game:GetService("ContextActionService"):BindActionToInputTypes("MouseMove", mouseMove, false, Enum.UserInputType.MouseMovement)
	
	runs:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function(dt)
		
		config.offx = script:WaitForChild("xoffset").Value
		config.zoom = script:WaitForChild("zoom").Value
		config.mousezoom = script:WaitForChild("mousezoom").Value
		
		camera.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, x, 0) * CFrame.Angles(y, 0, 0) -- rotate around player
		
		if Aiming == false then
			config.Sens = customSens

			local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Elastic,Enum.EasingDirection.Out,0, false,0)

			tween:Create(script.zoom, tweenInfo, {Value = config.mousezoom}):Play()

			tween:Create(script.xoffset, tweenInfo, {Value = 0}):Play()

			camera.CFrame = camera.CFrame * CFrame.new(config.offx, config.offy, config.zoom)
			
			
		end
	end)
end)
1 Like

Okay, first of all, ditch the CharacterAdded. Instead, assign a variable to the player’s character and update it each frame. If it does not exist, do not run the rest of the camera script. Otherwise, run the camera script for the remaining time of the frame.

You would need to put this in StarterPlayerScripts.

However, in my custom camera system for my FPS game, I put mine in the character itself. Then, you’d still be ditching the character added, but this might be more performant (unless your script does other stuff that does not require the character).

2 Likes

I had tried it before and I got the same bug or more bugs but now I tried it and if it worked, thanks for the help

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