Problem with functions after Jumpscare

Sup, I want to make jumpscare for me and my friend’s horror game. I’ve already got the jumpscare in working order, I want to tinker with the functions that happen after the jumpscare.

Those said functions just don’t seem to work after the jumpscare is finished. I checked if it only refuses to work with the very specific functions that are meant to happen after the jumpscare by adding Print(" ") It didn’t print out anything and there were no errors in the output.

This is the script (StarterGUI Client-Sided):

local cam = game.Workspace.CurrentCamera
local camPart = game.Workspace.JumpscareBox.JumpscareCam
local jumpscareTime = 5
local lighting = game.Lighting
local Screen = game.StarterGui.KillEffect.Frame
local Animation = script.Animation
local NPC = game.Workspace.JumpscareBox.a
local Player = game:GetService("Players")
local Spook = game.Workspace.SFX["FEAR HIT 04"]

local showMainMenuEvent = Instance.new("BindableEvent")
showMainMenuEvent.Name = "ShowMainMenu"
showMainMenuEvent.Parent = game.ReplicatedStorage

local sound = game.Workspace.SFX.Jumpscare

local remote = game.ReplicatedStorage.Jumpscare

remote.OnClientEvent:Connect(function()

	repeat
		cam.CameraType = Enum.CameraType.Scriptable
	until    cam.CameraType == Enum.CameraType.Scriptable

	local startTime = tick()

	cam.CFrame = camPart.CFrame
	
	local Anim = NPC.Humanoid:LoadAnimation(Animation)
	
	Anim:Play()
	
	script.Parent.BatteryHUD.Frame.Visible = false
	
	Screen.Visible = true

	lighting.ColorCorrection.Brightness = -0.2
	
	Spook:Play()

	sound:Play()
	repeat

		wait()

		local  endTime = tick()

		local randX = math.random(-300,150) / 500
		local randY = math.random(-300,150) / 500
		local randZ = math.random(-300,150) / 500

		cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(randX), math.rad(randY), math.rad(randZ))

	until endTime - startTime >= jumpscareTime
	
	--This is where it stops working
	
	print("cool")
	cam.CameraType = Enum.CameraType.Custom
	cam.CameraSubject = game.Players.LocalPlayer.Character
	script.Parent.BatteryHUD.Frame.Visible = false

	showMainMenuEvent:Fire() -- Fire the event to show the main menu


I’ve already talked about the problem in other posts but there was no solution. Would help a lot if someone explained the problem.