Help with jumpscare and menu system

I want to make a jumpscare play then make the game wait a few seconds then send the player to the main menu that is a surface GUI that can be seen by making a different part the camera (Witch is already done)

The problem is that I just don’t have the scripting knowledge to piece that together.

I tried to make that work using AI (ChatGPT) I know that ChatGPT scripts don’t work most of the time cuz of a few mistakes witch I fix before testing, but there was no luck this time. I couldn’t really find an another solution.

This is what I have written so far:
The jumpscare:

--The child of the script is the animation the entity plays--
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 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()
	
	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

	cam.CameraType = Enum.CameraType.Custom
	cam.CameraSubject = Player
	lighting.ColorCorrection.Brightness = 0


end)

The script in the hitbox part that triggers the jumpscare:


--There is a remote event in Replicated Storage named Jumpscare--
local hitbox = script.Parent
local cooldown = false
local remote = game.ReplicatedStorage.Jumpscare

hitbox.Touched:Connect(function(hit)

	local  plr = game.Players:GetPlayerFromCharacter(hit.Parent)

	if plr then 
		if not cooldown then
			local human = plr.Character.Humanoid		
			if human.Health > 0 then 
				cooldown = true 
				human.Health = 0
				remote:FireClient(plr)
				wait(2)
				cooldown = false
			end
		end		
	end
end)```



AND the script for the main menu itself:

–// Variables

local Sounds = game.Workspace.MainMenu.SFX

local player = game.Players.LocalPlayer

local pb = game.Workspace.MainMenu.Main.MainMenu.MainFrame.Buttons.Play

local cam = workspace.CurrentCamera

local camPart = workspace[“CameraPart”]

local mouse = game:GetService(“Players”).LocalPlayer:GetMouse()

–// Set cam

repeat

wait()

cam.CameraType = Enum.CameraType.Scriptable

until

cam.CameraType == Enum.CameraType.Scriptable

–// Move cam

local maxTilt = 5

game:GetService(“RunService”).RenderStepped:Connect(function()

cam.CFrame = camPart.CFrame * CFrame.Angles(

math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),

math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),

0

)

end)

–PlayFunction–

pb.MouseButton1Click:Connect(function()

Sounds.Click:Play()

end)


Now this is a lot I'm asking here, but I was simply left with no other choice, I've been working on this problem for a month and a half now and it would help the game greatly if someone came up how to combine all this together.
The person who will teach me how to make one script go to an another will deserve their own place in the Credits section. I know it's not much but it's the best I can do as a reward.
1 Like

I couldn’t write the last script in code format, I dunno what happened in the end, probably some kind of website bug.

This is the script in code format:

--// Variables
local Sounds = game.Workspace.MainMenu.SFX
local player = game.Players.LocalPlayer
local pb = game.Workspace.MainMenu.Main.MainMenu.MainFrame.Buttons.Play
local cam = workspace.CurrentCamera
local camPart = workspace["CameraPart"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

--// Set cam
repeat
	wait()
	cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 5
game:GetService("RunService").RenderStepped:Connect(function()
	cam.CFrame = camPart.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end)



--PlayFunction--

pb.MouseButton1Click:Connect(function()
	Sounds.Click:Play()
end)


Hey there! I understand your frustration and I’d be happy to help you out. To achieve what you want, you’ll need to modify the scripts slightly and make use of BindableEvents to communicate between the jumpscare and main menu scripts. Here’s a possible solution:

  1. In the jumpscare script, create a BindableEvent called “ShowMainMenu” in ReplicatedStorage:
local showMainMenuEvent = Instance.new("BindableEvent")
showMainMenuEvent.Name = "ShowMainMenu"
showMainMenuEvent.Parent = game.ReplicatedStorage
  1. After the jumpscare is finished, fire the “ShowMainMenu” event:
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = Player
lighting.ColorCorrection.Brightness = 0

showMainMenuEvent:Fire() -- Fire the event to show the main menu
  1. In the main menu script, create a function that sets up the main menu, and connect it to the “ShowMainMenu” event:
local function showMainMenu()
    -- Move your main menu setup code here
end

local showMainMenuEvent = game.ReplicatedStorage:WaitForChild("ShowMainMenu")
showMainMenuEvent.Event:Connect(showMainMenu)
  1. Initially, you need to call the showMainMenu function in the main menu script to display the main menu when the game starts:
showMainMenu() -- Call the function to display the main menu when the game starts

With these changes, after the jumpscare is finished, the “ShowMainMenu” event will be fired and the main menu will be displayed. Make sure you remove any duplicate code that may interfere with the functionality.

Now the scripts should be able to communicate with each other and display the main menu after the jumpscare. Good luck with your game!

A little problem with the Jumpscare script.
The funcitons it’s supposto do after the jumpscare simply don’t happen. (The brightness, setting the camera subject as the player ect.)
I forgot to mention the bug and I am very sorry for not doing so at the start, but this is how I updated the code cuz there might be a problem in that too.

The jumpscare script:

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()
	
	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

	cam.CameraType = Enum.CameraType.Custom
	cam.CameraSubject = Player
	lighting.ColorCorrection.Brightness = 0

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


end)

The menu script:

--// Variables
local Sounds = game.Workspace.MainMenu.SFX
local player = game.Players.LocalPlayer
local pb = game.Workspace.MainMenu.Main.MainMenu.MainFrame.Buttons.Play
local cam = workspace.CurrentCamera
local camPart = workspace["CameraPart"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
--// Set cam
repeat
	wait()
	cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local function showMainMenu()
	local maxTilt = 5
	game:GetService("RunService").RenderStepped:Connect(function()
		cam.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)



	--PlayFunction--

	pb.MouseButton1Click:Connect(function()
		Sounds.Click:Play()
	end)
end

local showMainMenuEvent = game.ReplicatedStorage:WaitForChild("ShowMainMenu")
showMainMenuEvent.Event:Connect(showMainMenu)


showMainMenu()


I also added the Bindable event in Replicated Storage.

In the Jumpscare script, you have:

cam.CameraSubject = Player

However, Player is actually a reference to the Players service, not the local player. You should change it to:

cam.CameraSubject = game.Players.LocalPlayer.Character

After making this change, your script should set the camera subject correctly after the jumpscare, and the functions following the jumpscare should work as intended.

Still no change. I don’t get why a lot stuff works for others except me.