How to make Proximity Prompt Trigger Cutscene

  1. What do you want to achieve?
    In my game, I have a talking NPC and would like the camera to cut to the NPC while it’s talking. I also want the camera to tween between two parts once during the conversation.

  2. What is the issue?
    When the proximity prompt is triggered the cutscene doesn’t play. I’ve followed AlvinBlox’s tutorial; however, he didn’t give an example with proximity prompts so I’ve been trying to do it myself. There are no other examples online that show me how to do it.

Here’s the Explorer set-up and scripts:
Screen Shot 2022-07-06 at 9.52.38 AM

game.Workspace["Hello Kitty"].HumanoidRootPart.ChatProximity.Triggered:Connect(function(player)
	local player = game.Players:GetPlayerFromCharacter(player.Parent)

	if player then
		game.ReplicatedStorage.RSCutscenes.HKCutscene:FireClient(player)
	end
	end)

Screen Shot 2022-07-06 at 9.53.48 AM

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera

function tween(part1,part2,cutsceneTime)

	local tweenInfo = TweenInfo.new(
		cutsceneTime,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame

	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()

	wait(cutsceneTime)

	camera.CameraType = Enum.CameraType.Custom
end

wait(2)
game.ReplicatedStorage.RSCutscenes.HKCutscene.OnClientEvent:Connect(function()
	tween(game.Workspace.CutsceneCams.HKCam,game.Workspace.CutsceneCams.HKCam2,7)
	tween(game.Workspace.CutsceneCams.HKCam2,game.Workspace.CutsceneCams.HKCam,10)
	--tween(game.Workspace.CutsceneCams.Cam3,game.Workspace.CutsceneCams.Cam4,9)
end)

Screen Shot 2022-07-06 at 9.53.23 AM

Screen Shot 2022-07-06 at 9.52.48 AM

Screen Shot 2022-07-06 at 9.53.07 AM

Script inside “Chat Proximity” which triggers GUI
I don’t know if this is relevant but thought I’d include it anyway!

local NPC = script.Parent.Parent.Parent
local TalkEvent = game:GetService("ReplicatedStorage"):FindFirstChild("NPCs").Npc
local Prox = script.Parent

script.Parent.Triggered:Connect(function(plr)
	plr.Character.Humanoid.WalkSpeed = 0
	plr.Character.Humanoid.JumpHeight = 0
	local NpcName = NPC.Name
	local M1 = script.Parent.Message1.Value
	local M2 = script.Parent.Message2.Value
	local M3 = script.Parent.Message3.Value
	local M4 = script.Parent.Message4.Value
	local M5 = script.Parent.Message5.Value

	TalkEvent:FireClient(plr,NpcName, M1, M2, M3, M4, M5, Prox)
end)
TalkEvent.OnServerEvent:Connect(function(plr)
	plr.Character.Humanoid.WalkSpeed = 16
	plr.Character.Humanoid.JumpHeight = 7.2
	plr.Character.Humanoid.JumpPower = 50

end)

Thank you for your time & help! :slight_smile:

It might be an error with variables.

game.Workspace[“Hello Kitty”].HumanoidRootPart.ChatProximity.Triggered:Connect(function(player)

if player then
	game.ReplicatedStorage.RSCutscenes.HKCutscene:FireClient(player)
end
end)

You had two variables with the same name, also you can get the player that triggered the prompt without using :GetPlayerFromCharacter()

2 Likes

Thank you for your extremely helpful reply! I’m wondering if you could go into more depth with your answer? (I’m a noob scripter) I’m not sure which two variables you’re saying have the same name or how to exactly fix the issue I’m having based on your reply. :sweat_smile:

the code from above is fixed, the problem was that you were already getting the player by doing this:

game.Workspace[“Hello Kitty”].HumanoidRootPart.ChatProximity.Triggered:Connect(function(player)

and you wrote a variable with the same name but different info:

local player = game.Players:GetPlayerFromCharacter(player.Parent)
1 Like

I see!! Thank you so very much for teaching me something new & for helping me fix the problem! :slight_smile:

1 Like