Camera freezing when tabbing out and back in after first death (long scripts but help appreciated)

Hello devs
im bringing an issue up that i took a break on but am hoping its the last small fix that will ever be needed with this script

recently i solved with help the issue of the camera locking up after 1 death but another issue that popped up when i respawn is not the camera locking instantly but locking up when i tab out of roblox or roblox studio and then back in

heres the locking up on death post i made

if that helps

screenshots dont really help anymore so i will send a short clip of my issue

External Media

i also guess a single screenshot would help it doesnt snap up but it does lock the camera in the last known position of the mouse


here are the two last scripts from the other forum post that were given.

CameraClient

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local InputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local CameraRemoteEvent = ReplicatedStorage:WaitForChild("CameraRemoteEvent")
local PlayButtonPressedEvent = ReplicatedStorage:WaitForChild("PlayButtonPressedEvent")
local cameraUpdateConnection = nil
local mouseMovedConnection = nil
local cameraInitialized = false
local cameraShakeEffect = nil
local isJumpScareActive = false

local function initializeCamera(character)
	wait(0.5)

	local Camera = game.Workspace.CurrentCamera
	character = character or player.Character or player.CharacterAdded:Wait()

	local humanoid = character:WaitForChild("Humanoid", 10)
	if not humanoid then
		return
	end

	local Head = character:WaitForChild("Head", 10)
	local Torso = character:WaitForChild("Torso", 10)
	local RootPart = character:WaitForChild("HumanoidRootPart", 10)
	local Neck = Torso:WaitForChild("Neck", 10)

	if not Head or not Torso or not RootPart or not Neck then
		return
	end

	Camera.FieldOfView = 90
	Camera.CameraType = Enum.CameraType.Scriptable
	InputService.MouseBehavior = Enum.MouseBehavior.LockCenter

	local v3 = Vector3.new
	local cf = CFrame.new
	local inverse = cf().inverse
	local fromAxisAngle = CFrame.fromAxisAngle
	local atan, atan2 = math.atan, math.atan2
	local acos = math.acos

	local function toAxisAngleFromVector(v)
		local z = v.z
		return z * z < 0.99999 and v3(v.y, -v.x, 0).unit * acos(-z) or v3()
	end

	local function AxisAngleLookOrientation(c, v, t)
		local c = c - c.p
		local rv = (inverse(c) * v).unit
		local rz = rv.z
		return rz * rz < 0.99999 and c * fromAxisAngle(v3(rv.y, -rv.x, 0), acos(-rz) * (t or 1)) or c
	end

	local function AxisAngleLookNew(v, t)
		local rv = v.unit
		local rz = rv.z
		return rz * rz < 0.99999 and fromAxisAngle(v3(rv.y, -rv.x, 0), acos(-rz) * (t or 1)) or cf()
	end

	local function AxisAngleLook(c, v, t)
		local rv = (inverse(c) * v).unit
		local rz = rv.z
		return rz * rz < 0.99999 and c * fromAxisAngle(v3(rv.y, -rv.x, 0), acos(-rz) * (t or 1)) or c
	end

	local Sensitivity = 0.005
	local CameraDirection = Vector3.new(0, 0, 1)

	local function EulerAnglesYX(l)
		local x, z = l.x, l.z
		return atan(l.y / (x * x + z * z) ^ 0.5), -atan2(l.x, -z)
	end

	local function AnglesXY(l)
		local z = l.z
		return atan2(l.y, -z), -atan2(l.x, -z)
	end

	local function MouseMoved(Input)
		if Input.UserInputType == Enum.UserInputType.MouseMovement then
			local dx, dy = Input.Delta.x * Sensitivity, Input.Delta.y * Sensitivity
			local m2 = dx * dx + dy * dy
			if m2 > 0 then
				CameraDirection = (AxisAngleLookOrientation(RootPart.CFrame, CameraDirection) * fromAxisAngle(v3(-dy, -dx, 0), m2 ^ 0.5)).lookVector
			end
			local RootOrientation = RootPart.CFrame - RootPart.Position
			local RelativeDirection = RootOrientation:inverse() * CameraDirection
			local AngX, AngY = AnglesXY(RelativeDirection)
			if AngX < -1.57 * 11 / 12 then
				local y, z, c, s = RelativeDirection.y, RelativeDirection.z, math.cos(-1.57 * 11 / 12 - AngX), -math.sin(-1.57 * 11 / 12 - AngX)
				z, y = z * c - y * s, z * s + y * c
				CameraDirection = RootOrientation * v3(RelativeDirection.x < 0 and -(1 - y * y - z * z) ^ 0.5 or (1 - y * y - z * z) ^ 0.5, y, z)
			elseif AngX > 1.57 * 11 / 12 then
				local y, z, c, s = RelativeDirection.y, RelativeDirection.z, math.cos(1.57 * 11 / 12 - AngX), -math.sin(1.57 * 11 / 12 - AngX)
				z, y = z * c - y * s, z * s + y * c
				CameraDirection = RootOrientation * v3(RelativeDirection.x < 0 and -(1 - y * y - z * z) ^ 0.5 or (1 - y * y - z * z) ^ 0.5, y, z)
			end
		end
	end

	local function reconnectMouseMoved()
		if mouseMovedConnection then
			mouseMovedConnection:Disconnect()
		end
		mouseMovedConnection = InputService.InputChanged:Connect(MouseMoved)
		print("MouseMoved connected")  -- Debug message
	end

	reconnectMouseMoved()

	Neck.C1 = cf()

	local _
	local DirectionBound = 3.14159 / 3
	local CurrentAngY = 0

	local function CameraUpdate(deltaTime)
		if _G.isJumpScareActive then
			return
		end

		if cameraShakeEffect then
			cameraShakeEffect(deltaTime)
		end

		Camera.CameraType = Enum.CameraType.Scriptable
		local cx, cz = CameraDirection.x, CameraDirection.z
		local rvx, rvz = RootPart.Velocity.x, RootPart.Velocity.z
		if rvx * rvx + rvz * rvz > 4 and cx * rvx + cz * rvz < -0.5 * (cx * cx + cz * cz) ^ 0.5 * (rvx * rvx + rvz * rvz) ^ 0.5 then
			DirectionBound = math.min(DirectionBound * 0.9, math.abs(CurrentAngY * 0.9))
		else
			DirectionBound = DirectionBound * 0.1 + 3.14159 / 3 * 0.9
		end
		local AngX, AngY = EulerAnglesYX((RootPart.CFrame - RootPart.Position):inverse() * CameraDirection)
		if AngY > DirectionBound then
			RootPart.CFrame = RootPart.CFrame * CFrame.Angles(0, AngY - DirectionBound, 0)
		elseif AngY < -DirectionBound then
			RootPart.CFrame = RootPart.CFrame * CFrame.Angles(0, AngY + DirectionBound, 0)
		end
		_, CurrentAngY = EulerAnglesYX((RootPart.CFrame - RootPart.Position):inverse() * CameraDirection)
		local CameraOrientation = AxisAngleLookNew((RootPart.CFrame - RootPart.Position):inverse() * CameraDirection, 1)
		Neck.C0 = CFrame.new(0, 1, 0) * CameraOrientation * CFrame.new(0, 0.5, 0)

		local PreCam = AxisAngleLook(RootPart.CFrame * cf(0, 1, 0), RootPart.CFrame * v3(0, 1, 0) + CameraDirection) * CFrame.new(0, 0.825, 0)
		local Zoom = -0.5
		Camera.CFrame = PreCam * CFrame.new(0, 0, Zoom)
	end

	if cameraUpdateConnection then
		RunService:UnbindFromRenderStep("UpdateCamera")
		cameraUpdateConnection = nil
	end

	RunService:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value, CameraUpdate)
	cameraUpdateConnection = "UpdateCamera"
	print("CameraUpdate connected")  -- Debug message

	local function OnFocusGained()
		reconnectMouseMoved()
		InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		print("Window focused, MouseMoved reconnected")  -- Debug message
	end

	local function OnFocusLost()
		if mouseMovedConnection then
			mouseMovedConnection:Disconnect()
		end
		InputService.MouseBehavior = Enum.MouseBehavior.Default
		print("Window focus lost, MouseMoved disconnected")  -- Debug message
	end

	InputService.WindowFocused:Connect(OnFocusGained)
	InputService.WindowFocusReleased:Connect(OnFocusLost)

	_G.setCameraShakeEffect = function(effectFunction)
		cameraShakeEffect = effectFunction
	end

	_G.setJumpScareActive = function(active)
		isJumpScareActive = active
	end
end

local function cleanUp()
	if mouseMovedConnection then
		mouseMovedConnection:Disconnect()
		mouseMovedConnection = nil
		print("MouseMoved disconnected during cleanup")  -- Debug message
	end
	if cameraUpdateConnection then
		RunService:UnbindFromRenderStep("UpdateCamera")
		cameraUpdateConnection = nil
		print("CameraUpdate disconnected during cleanup")  -- Debug message
	end
end

CameraRemoteEvent.OnClientEvent:Connect(function(action)
	if action == "InitializeCamera" then
		cleanUp()
		if cameraInitialized then
			initializeCamera()
		end
	elseif action == "StartCamera" then
		cleanUp()
		cameraInitialized = true
		initializeCamera()
	end
end)

player.CharacterAdded:Connect(function(character)
	wait(0.5)
	if cameraInitialized then
		cleanUp()
		initializeCamera(character)
	end
end)

player.CharacterRemoving:Connect(cleanUp)

jumpscare effect

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local Camera = Workspace.CurrentCamera

local respawnEvent = ReplicatedStorage:WaitForChild("RespawnRequest")
local getMimickedPlayerId = ReplicatedStorage:WaitForChild("GetMimickedPlayerId")
local killLoggingEvent = ReplicatedStorage:WaitForChild("KillLoggingEvent")

_G.isJumpScareActive = false
_G.isRespawning = false

-- Function to set the dummy's appearance
local function setDummyAppearance(dummy, userId)
	local success, humanoidDescription = pcall(function()
		return Players:GetHumanoidDescriptionFromUserId(userId)
	end)
	if success and humanoidDescription then
		local humanoid = dummy:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid:ApplyDescription(humanoidDescription)

			-- Remove all hats except "MonsterHead"
			for _, accessory in ipairs(dummy:GetChildren()) do
				if accessory:IsA("Accessory") and accessory.Name ~= "MonsterHead" then
					accessory:Destroy()
				end
			end
		else
			warn("Humanoid not found in dummy")
		end
	else
		warn("Failed to get humanoid description for dummy")
	end
end

-- Function to play animation on dummy
local function playAnimationOnDummy(dummy)
	local humanoid = dummy:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if not animator then
			animator = Instance.new("Animator")
			animator.Parent = humanoid
		end

		local animation = Instance.new("Animation")
		animation.AnimationId = "rbxassetid://18550795494"

		local animationTrack = animator:LoadAnimation(animation)
		animationTrack:Play()
		animationTrack:AdjustSpeed(1)

		-- Gradually slow down the animation playback speed
		local startTime = tick()
		local duration = 2 -- Duration over which to slow down
		local initialSpeed = 1
		local targetSpeed = 0.75

		RunService.Heartbeat:Connect(function()
			local elapsedTime = tick() - startTime
			if elapsedTime <= duration then
				local newSpeed = initialSpeed + (targetSpeed - initialSpeed) * (elapsedTime / duration)
				animationTrack:AdjustSpeed(newSpeed)
			else
				animationTrack:AdjustSpeed(targetSpeed)
			end
		end)
	else
		warn("Humanoid not found in dummy")
	end
end

-- Create or get the Atmosphere object
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere")
if not atmosphere then
	atmosphere = Instance.new("Atmosphere")
	atmosphere.Parent = Lighting
end

-- Initial Atmosphere settings
local initialDensity = 0.425
local initialColor = Color3.fromRGB(199, 199, 199)
local initialDecay = Color3.fromRGB(106, 112, 125)
local initialGlare = 0
local initialHaze = 0

-- Jump scare Atmosphere settings
local jumpScareDensity = 1
local jumpScareColor = Color3.fromRGB(0, 0, 0)
local jumpScareDecay = Color3.fromRGB(0, 0, 0)
local jumpScareGlare = 0
local jumpScareHaze = 10

-- Function to set Atmosphere settings
local function setAtmosphereSettings(density, color, decay, glare, haze)
	atmosphere.Density = density
	atmosphere.Color = color
	atmosphere.Decay = decay
	atmosphere.Glare = glare
	atmosphere.Haze = haze
end

local function fadeOutSound(soundInstance, startFadeTime, fadeDuration)
	local startTime = tick()
	local initialVolume = soundInstance.Volume

	local function onRenderStep()
		local elapsedTime = tick() - startTime
		if elapsedTime >= startFadeTime and elapsedTime < startFadeTime + fadeDuration then
			local fadeElapsedTime = elapsedTime - startFadeTime
			soundInstance.Volume = initialVolume * (1 - (fadeElapsedTime / fadeDuration))
		elseif elapsedTime >= startFadeTime + fadeDuration then
			soundInstance.Volume = 0
			soundInstance:Destroy()
			RunService:UnbindFromRenderStep("fadeOutSound")
		end
	end

	RunService:BindToRenderStep("fadeOutSound", Enum.RenderPriority.Camera.Value, onRenderStep)
end

local function playRandomJumpScareSound()
	local jumpScareSoundsFolder = ReplicatedStorage:FindFirstChild("JumpScareSounds")
	if not jumpScareSoundsFolder then
		warn("JumpScareSounds folder not found in ReplicatedStorage")
		return
	end

	local sounds = {
		jumpScareSoundsFolder:FindFirstChild("JumpScare1"),
		jumpScareSoundsFolder:FindFirstChild("JumpScare2"),
		jumpScareSoundsFolder:FindFirstChild("JumpScare3")
	}

	-- Pick one random sound to play
	local soundToPlay = sounds[math.random(#sounds)]

	if soundToPlay then
		local soundInstance = soundToPlay:Clone()
		soundInstance.Volume = 1
		soundInstance.Parent = Camera
		soundInstance:Play()
		soundInstance.Ended:Connect(function()
			soundInstance:Destroy()
		end)
	else
		warn("Selected jump scare sound not found in JumpScareSounds folder")
	end
end

local function playJumpScareStaticSound()
	local jumpScareSoundsFolder = ReplicatedStorage:FindFirstChild("JumpScareSounds")
	if not jumpScareSoundsFolder then
		warn("JumpScareSounds folder not found in ReplicatedStorage")
		return
	end

	local staticSound = jumpScareSoundsFolder:FindFirstChild("Static")
	if not staticSound then
		warn("Static sound not found in JumpScareSounds folder")
		return
	end

	local soundInstance = staticSound:Clone()
	soundInstance.Parent = Camera
	soundInstance:Play()

	-- Fade out the sound starting after 5 seconds, over a duration of 5 seconds
	fadeOutSound(soundInstance, 5, 5)
end

local function setCameraToJumpScareCam(jumpScareCam)
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = jumpScareCam.CFrame * CFrame.new(0, 0, -5)

	local function updateCamera()
		if jumpScareCam.Parent then
			Camera.CFrame = jumpScareCam.CFrame * CFrame.new(0, 0, -5)
		else
			Camera.CameraType = Enum.CameraType.Custom
			Camera.CameraSubject = player.Character:WaitForChild("Humanoid")
			RunService:UnbindFromRenderStep("UpdateCamera")
			_G.isJumpScareActive = false
			-- Reset Atmosphere settings
			setAtmosphereSettings(initialDensity, initialColor, initialDecay, initialGlare, initialHaze)
			-- Re-enable inventory, leaderboard, and chat bar
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		end
	end

	RunService:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value, updateCamera)
end

local function spawnExistingDummy()
	local jumpScareFolder = ReplicatedStorage:FindFirstChild("JumpScare")
	if not jumpScareFolder then
		warn("JumpScare folder not found in ReplicatedStorage")
		return nil
	end

	local dummy = jumpScareFolder:FindFirstChild("Dummy")
	if not dummy then
		warn("Dummy not found in JumpScare folder")
		return nil
	end

	local clonedDummy = dummy:Clone()
	clonedDummy.Parent = Workspace

	-- Set the position and orientation of each part
	local function setPartPosition(part, position)
		part.Position = position
		part.Orientation = Vector3.new(-3.999, 178.998, 0.07)
	end

	setPartPosition(clonedDummy.Head, Vector3.new(3.15, 385.749, 93.454))
	setPartPosition(clonedDummy.Torso, Vector3.new(3.15, 384.253, 93.349))
	setPartPosition(clonedDummy["Right Arm"], Vector3.new(1.65, 384.254, 93.323))
	setPartPosition(clonedDummy["Left Arm"], Vector3.new(4.65, 384.251, 93.375))
	setPartPosition(clonedDummy["Right Leg"], Vector3.new(2.65, 382.258, 93.201))
	setPartPosition(clonedDummy["Left Leg"], Vector3.new(3.65, 382.257, 93.218))
	setPartPosition(clonedDummy.HumanoidRootPart, Vector3.new(3.15, 384.253, 93.349))

	clonedDummy.PrimaryPart = clonedDummy.HumanoidRootPart
	clonedDummy:SetPrimaryPartCFrame(CFrame.new(Vector3.new(3.15, 384.253, 93.349)) * CFrame.Angles(math.rad(-3.999), math.rad(178.998), math.rad(0.07)))

	return clonedDummy
end

local function tweenDummyBackwards(dummy)
	wait(2)  -- Wait for 2 seconds before moving
	local initialCFrame = dummy.PrimaryPart.CFrame
	local goalCFrame = initialCFrame * CFrame.new(0, 0, 4)  -- Adjusted to move backwards by 4 studs

	local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tween = TweenService:Create(dummy.PrimaryPart, tweenInfo, {CFrame = goalCFrame})

	tween:Play()
	tween.Completed:Connect(function()
		-- Reset dummy to initial position after the tween
		dummy:SetPrimaryPartCFrame(initialCFrame)
	end)
end

local function spawnAndSetJumpScareCam()
	local jumpScareFolder = ReplicatedStorage:FindFirstChild("JumpScare")
	if not jumpScareFolder then
		warn("JumpScare folder not found in ReplicatedStorage")
		return nil
	end

	local jumpScareCam = jumpScareFolder:FindFirstChild("JumpScareCam")
	if not jumpScareCam then
		warn("JumpScareCam not found in JumpScare folder")
		return nil
	end

	local clonedJumpScareCam = jumpScareCam:Clone()
	clonedJumpScareCam.Name = "ActiveJumpScareCam"
	clonedJumpScareCam.Parent = Workspace

	_G.isJumpScareActive = true
	_G.setJumpScareActive(true)
	setCameraToJumpScareCam(clonedJumpScareCam)

	-- Set jump scare Atmosphere settings
	setAtmosphereSettings(jumpScareDensity, jumpScareColor, jumpScareDecay, jumpScareGlare, jumpScareHaze)

	-- Enable the JumpScareGui ScreenGui
	local gui = player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("JumpScareGui")
	if gui then
		gui.Enabled = true
	end

	-- Play a random jump scare sound
	playRandomJumpScareSound()

	-- Play the static sound
	playJumpScareStaticSound()

	-- Hide inventory, leaderboard, and chat bar
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

	-- Spawn the existing dummy
	local dummy = spawnExistingDummy()

	-- Get the UserId of the mimicked player from the server if killed by AI
	local wasKilledByAI, mimickedUserId = pcall(function()
		return getMimickedPlayerId:InvokeServer()
	end)

	if wasKilledByAI and mimickedUserId then
		setDummyAppearance(dummy, mimickedUserId)
	else
		warn("Player was not killed by AI or failed to get mimicked player UserId from server")
	end

	-- Play the animation on the dummy immediately
	playAnimationOnDummy(dummy)

	-- Tween the dummy backwards
	tweenDummyBackwards(dummy)

	return clonedJumpScareCam, dummy
end

local function makeHeadInvisible(character)
	local head = character:FindFirstChild("Head")
	if head then
		head.Transparency = 1
		for _, child in ipairs(head:GetChildren()) do
			if child:IsA("Decal") or child:IsA("FaceInstance") then
				child:Destroy()
			end
		end
	end
end

local function fadeTextLabelIn(textLabel, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local goal = {TextTransparency = 0}
	local tween = TweenService:Create(textLabel, tweenInfo, goal)
	tween:Play()
end

local function fadeTextLabelOut(textLabel, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local goal = {TextTransparency = 1}
	local tween = TweenService:Create(textLabel, tweenInfo, goal)
	tween:Play()
end

local function fadeTextLabelBackgroundIn(textLabel, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local goal = {BackgroundTransparency = 0}
	local tween = TweenService:Create(textLabel, tweenInfo, goal)
	tween:Play()
end

local function handleYouDiedText()
	local jumpScareGui = player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("JumpScareGui")
	if jumpScareGui then
		local frame2 = jumpScareGui:FindFirstChild("Frame2")
		if frame2 then
			local deathText = frame2:FindFirstChild("YouDied")
			local timeAliveText = frame2:FindFirstChild("TimeAlive")
			local darkFadeText = frame2:FindFirstChild("DarkFade")

			if deathText then
				print("YouDied TextBox found, starting sequence")  -- Debug message
				deathText.TextTransparency = 1 -- Ensure initial state is invisible
				wait(1) -- Wait 1 second before starting the fade-in
				fadeTextLabelIn(deathText, 1) -- Fade in over 1 second
				wait(2) -- Wait for 2 seconds while the text is visible
				fadeTextLabelOut(deathText, 2) -- Fade out over 2 seconds
				print("YouDied TextBox sequence complete")  -- Debug message

				if timeAliveText then
					print("TimeAlive TextBox found, starting sequence")  -- Debug message
					timeAliveText.TextTransparency = 1 -- Ensure initial state is invisible
					wait(0.5) -- Wait 0.5 seconds before starting the fade-in
					fadeTextLabelIn(timeAliveText, 1) -- Fade in over 1 second
					wait(2) -- Wait for 2 seconds while the text is visible
					fadeTextLabelOut(timeAliveText, 2) -- Fade out over 2 seconds
					print("TimeAlive TextBox sequence complete")  -- Debug message
				else
					warn("TimeAlive TextBox not found in Frame2")  -- Debug message
				end
			else
				warn("YouDied TextBox not found in Frame2")  -- Debug message
			end

			if darkFadeText then
				darkFadeText.ZIndex = 50 -- Ensure the TextLabel is on top of everything
				darkFadeText.BackgroundTransparency = 1 -- Ensure initial state is fully transparent
				print("DarkFade TextLabel found, starting sequence")  -- Debug message
				wait(1) -- Wait 1 second after the jump scare animation starts
				print("Fading in DarkFade TextLabel")  -- Debug message
				fadeTextLabelBackgroundIn(darkFadeText, 1) -- Fade in over 1 second
				print("DarkFade TextLabel sequence complete")  -- Debug message
			else
				warn("DarkFade TextLabel not found in Frame2")  -- Debug message
			end
		else
			warn("Frame2 not found in JumpScareGui")  -- Debug message
		end
	else
		warn("JumpScareGui not found in PlayerGui")  -- Debug message
	end
end

local function despawnJumpScareCam()
	local jumpScareCam = Workspace:FindFirstChild("ActiveJumpScareCam")
	if jumpScareCam then
		jumpScareCam:Destroy()
	end
	_G.isJumpScareActive = false
	_G.setJumpScareActive(false)
end

local function onPlayerDeath()
	-- Set jump scare Atmosphere settings immediately upon death
	setAtmosphereSettings(jumpScareDensity, jumpScareColor, jumpScareDecay, jumpScareGlare, jumpScareHaze)

	-- Ensure the JumpScareGui stays visible
	local jumpScareGui = player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("JumpScareGui")
	if jumpScareGui then
		jumpScareGui.Enabled = true
	else
		warn("JumpScareGui not found in PlayerGui")
	end

	local jumpScareCam, dummy = spawnAndSetJumpScareCam()

	-- Handle the "You Died" text appearance
	spawn(handleYouDiedText)

	-- Ensure the player respawns only once
	if not _G.isRespawning then
		_G.isRespawning = true
		respawnEvent:FireServer()
	end

	-- Cleanup after player respawn
	player.CharacterAdded:Wait()
	_G.isRespawning = false

	-- Despawn the jump scare camera and dummy
	if jumpScareCam then
		jumpScareCam:Destroy()
	end
	if dummy then
		dummy:Destroy()
	end

	-- Disable the JumpScareGui
	if jumpScareGui then
		jumpScareGui.Enabled = false
	end

	-- Re-enable inventory, leaderboard, and chat bar
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

	-- Reset Atmosphere settings
	setAtmosphereSettings(initialDensity, initialColor, initialDecay, initialGlare, initialHaze)
end

local function initializeCharacter()
	local character = player.Character or player.CharacterAdded:Wait()
	while not character.Parent do
		wait()
	end
	local primaryPart = character:WaitForChild("HumanoidRootPart", 10)
	local humanoid = character:WaitForChild("Humanoid", 10)

	if primaryPart and humanoid then
		makeHeadInvisible(character)
		humanoid.Died:Connect(onPlayerDeath)
	end
end

player.CharacterAdded:Connect(initializeCharacter)
initializeCharacter()

-- Set initial Atmosphere settings
setAtmosphereSettings(initialDensity, initialColor, initialDecay, initialGlare, initialHaze)

respawnEvent.OnClientEvent:Connect(function()
	if player.Character then
		player.Character:BreakJoints()
		-- Get the UserId of the mimicked player from the server and set the player's appearance
		local success, mimickedUserId = pcall(function()
			return getMimickedPlayerId:InvokeServer()
		end)

		if success and mimickedUserId then
			-- setPlayerAppearance(mimickedUserId) -- Removed as it requires server-side execution
		else
			warn("Failed to get mimicked player UserId from server")
		end
	end
end)

-- Cleanup on respawn
player.CharacterAdded:Connect(function()
	wait(1)
	despawnJumpScareCam()

	-- Re-enable GUI elements after respawn
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end)

both reside in starterplayscripts

both handle the camera in certain ways

if anyone is capable of helping it would be so much appreciated thanks for listening

no biters??

(charactersssssssss)

just gonna shine some light back on this as ive found no issue still :confused:

Tabbing out can cause the mouse behavior to change. To solve it, just change it back to lock center.

InputService:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
	InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
1 Like

Hi, sorry for the late reply so the script for the camera originally did that and it works fine when i first spawned in but after dying and i tab out and back in it locks up so im thinking its mainly the jumpscare effect script, thank you though!

just gonna shine some more light on this issue as i really hope someone can help

still going strong on tryna solve this