Screen Shake (Humanoid.CameraOffset) doesn't work after player dies?

I’ve tried multiple fixes, such as replacing variables with their non-variable counterparts (if that makes sense).

Basically, when the player dies, the magnitude of HumanoidRootPart and Origin (origin being where the screen shake is originating from, it IS a vector3 position) becomes 200-300. So, I thought “Okay, this is the issue.”

Although it clearly IS a part of the issue, it isn’t the whole issue. When I brought the player over to the area that the script thought was correct, the screen shake STILL didn’t work.

Is there any obvious issue with my code? If not, do you have any hypotheses?

local function screenShake(Origin, Range, Intensity, shakeCount)
	print(Origin, Character:FindFirstChild("HumanoidRootPart").Position, (Origin - Character:FindFirstChild("HumanoidRootPart").Position).Magnitude)
	if (Origin - HumanoidRootPart.Position).Magnitude > Range then return end
		for i = 1, shakeCount do
			Humanoid.CameraOffset = - Intensity + i/10, 5 + Intensity - i/10), math.random(-5 - Intensity + i/10, 5 + Intensity - i/10), math.random(-5 - Intensity + i/10, 5 + Intensity - i/10))
		Humanoid.CameraOffset =,0,0)

Well, you didn’t provide the Humanoid variable, so it is probably referring to the humanoid you define initially.

When the player dies, the humanoid becomes nil after the player respawns.

This is a client script - Player, Character, HumanoidRootPart, and Humanoid are provided at the start of the script.

I use Character:WaitForChild(“Humanoid”)

Right, I know that. But if the humanoid variable is defined once, and the character respawns, the humanoid is destroyed and the variable becomes nil, because its a reference to a nonexistent instance.
Try to define the humanoid variable in the function, and check it it exists before trying shake the screen.

1 Like