Why does this custom camera script kill me?

When scrolling with your mouse during this, it just kills you. Why? I don’t know.




local inputserv = game:GetService("UserInputService")

local mouse = game.Players.LocalPlayer:GetMouse()
zoomstat = 50
zoomoutlimit = 1200
zoomsmallest = 10
local runserv = game:GetService("RunService")
runserv.RenderStepped:Connect(function() 
	if workspace.CurrentCamera.CameraType ~= Enum.CameraType.Scriptable then
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	end
	if workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable then
		if game.Players.LocalPlayer.Character ~= nil then
			local zs = game.Players.LocalPlayer.Character:FindFirstChild("Head")
			if zs ~= nil then
				workspace.CurrentCamera.CFrame = CFrame.lookAt(game.Players.LocalPlayer.Character.Head.Position + Vector3.new(0,tonumber(zoomstat),0), game.Players.LocalPlayer.Character.Head.Position)
			end	
		end
	end
end)
--inputserv.InputBegan:Connect(function(input,gamepr)
--	if input.UserInputType == Enum.UserInputType.MouseWheel then
		
--	end
--end)
inputserv.InputChanged:connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseWheel then
		local the = input.Position.Z > 0 and "UP" or "DOWN"
		if the == "UP" then
			if (zoomstat + 1) >= zoomoutlimit then
				zoomstat = tonumber(zoomoutlimit)
			else
				zoomstat = tonumber((zoomstat + 1))
			end
		end
		if the == "DOWN" then
			if (zoomstat - 1) <= zoomsmallest then
				zoomstat = tonumber(zoomsmallest)
			else
				zoomstat = tonumber(zoomstat - 1)	
			end
		end
	end
	end)
--mouse.WheelBackward:Connect(function()
--	if (zoomstat + 25) >= zoomoutlimit then
--		zoomstat = zoomoutlimit
--	else
--		zoomstat = zoomstat + 25	
--	end
--end)
--mouse.WheelForward:Connect(function()
--	if (zoomstat - 25) <= zoomsmallest then
--		zoomstat = 10
--	else
		
		
--		zoomstat = zoomstat - 25	
--		end
--end)
1 Like

Because you are moving the head, this causes the player to die.

Try check out the Motor6Ds inside the character instead of moving the head directly:

R6:
image

R15:
image

It’s moving the camera. It completely just deletes the character, so if it were to be updating the head it would kill me and keep my body there.

Does it run fine when not involving joints/body parts?

Yeah… I’m super lost. I have no idea what causes it.

In this block of code, change Vector3.new(0,tonumber(zoomstat),0) to Vector3.new(0,tonumber(zoomstat),-1)

The issue is having the camera be directly above the players head, causing the cframe.lookAt() function to spazz out, which for some reason causes the player to just, disappear…

Don’t ask me why or how this happens, all I know is that adding a number that’s not 0 to the z or x axis in the Vector3 will keep your character from being sent to the void.

example:

if zs ~= nil then
	workspace.CurrentCamera.CFrame = CFrame.lookAt(game.Players.LocalPlayer.Character.Head.Position + Vector3.new(0,tonumber(zoomstat),-1), game.Players.LocalPlayer.Character.Head.Position)
end	

Hope this helps!

1 Like