Activating Cutscene via ClickDetector

So, I’m currently working on adding cutscenes to a game I’m making. I’m planning on activating them via a ClickDetector in a part. However, I’m not extremely skilled at scripting to pull that off. For the actual cutscenes, I’m using Cutscenify and the Part Touched script. I tried replacing any “Touch” with “Click” in the script, as well as specifying the part where I want the cutscene to play, but those didn’t work. If anyone has a solution to suggest, I would be happy to try it out.

Thank you.

Could you show us the script possibly? Specifically the current Touched Event and what you changed on it would be really helpful. :slight_smile:

Generally speaking though:

local function cutScene()
-- your cutscene script is here or whatever you use to start it
end

-- What you're currently doing if I'm understanding correctly.
workspace.ThePartNameYouAreTouchingToActivateIt.Touched:Connect(cutScene)

-- If you wanted that to be on a ClickDetector, you'd have to add a ClickDetector to the part and do the following.
workspace.ThePartYouUsedToBeTouchingToActivateIt.ClickDetector.MouseClick:Connect(cutScene)
1 Like

Here’s the modified script in question:

If you find any bugs, please contact me via Twitter. @_inventfvl or @cutscenify

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local camera = workspace.CurrentCamera
local cutsceneName = script.CutsceneName
if not cutsceneName then
	warn("CutsceneName does not exist, cutscene cannot run.")
end
local easingStyle
local easingDirection
local canPlayCutscene = true
local didLastPointDoImmediateSwitch = false
local partOfCutsceneDuration = 0
local cutsceneDuration = 0
local cutsceneParts = workspace:WaitForChild(cutsceneName.Value)
local partToClickString = "CutscenePartClick_" .. cutsceneName.Value
local doesStartAtPlayer = script.DoesStartAndEndAtPlayer.Value
local timetaken = 0
local count = 0
local tweeningCompleted = false
local endTweenComplete = false
local cutscenePart
local Character = Players.LocalPlayer.Character
local lastCutscenePart
local childcount = 0
local fieldOfView = 70
local originalCFrame


local function PlayPartOfCutscene(cameraInstance, pointInstance, fieldOfView, isFirst)
	camera.CameraType = Enum.CameraType.Scriptable
	lastCutscenePart = #pointInstance.Parent:GetChildren()
	local tweeningTable = {
		CFrame = pointInstance.CFrame
	}
	if pointInstance.EasingDirection.Value == 1 then
		easingDirection = Enum.EasingDirection.In
	elseif pointInstance.EasingDirection.Value == 2 then
		easingDirection = Enum.EasingDirection.Out
	elseif pointInstance.EasingDirection.Value == 3 then
		easingDirection = Enum.EasingDirection.InOut
	end
				
	if pointInstance.EasingStyle.Value == 1 then
		easingStyle = Enum.EasingStyle.Linear
	elseif pointInstance.EasingStyle.Value == 2 then
		easingStyle = Enum.EasingStyle.Quad
	elseif pointInstance.EasingStyle.Value == 3 then
		easingStyle = Enum.EasingStyle.Quart
	elseif pointInstance.EasingStyle.Value == 4 then
		easingStyle = Enum.EasingStyle.Quint
	elseif pointInstance.EasingStyle.Value == 5 then
		easingStyle = Enum.EasingStyle.Sine
	elseif pointInstance.EasingStyle.Value == 6 then
		easingStyle = Enum.EasingStyle.Back
	elseif pointInstance.EasingStyle.Value == 7 then
		easingStyle = Enum.EasingStyle.Bounce
	elseif pointInstance.EasingStyle.Value == 8 then
		easingStyle = Enum.EasingStyle.Circular
	elseif pointInstance.EasingStyle.Value == 9 then
		easingStyle = Enum.EasingStyle.Cubic
	elseif pointInstance.EasingStyle.Value == 10 then
		easingStyle = Enum.EasingStyle.Elastic
	elseif pointInstance.EasingStyle.Value == 11 then
		easingStyle = Enum.EasingStyle.Exponential
	end
	
	local tweenInfoCamMovement = TweenInfo.new(tonumber(pointInstance:WaitForChild("TransitionTime").Value), easingStyle, easingDirection, 0, false, 0)
	if isFirst then
		local tweenInfoCamMovement = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	end
	local tween = TweenService:Create(cameraInstance, tweenInfoCamMovement, tweeningTable)
	if not didLastPointDoImmediateSwitch then
		tween:Play()
	end
	
	local FOVTweeningTable = {
		FieldOfView = fieldOfView
	}
	local FormattedTweenInfo = TweenInfo.new(tonumber(pointInstance:WaitForChild("TransitionTime").Value), easingStyle, easingDirection, 0, false, 0)
	local FOVTween = TweenService:Create(camera, FormattedTweenInfo, FOVTweeningTable)
	if not didLastPointDoImmediateSwitch then
		FOVTween:Play()
	end
	
	tweeningCompleted = false
	if didLastPointDoImmediateSwitch then
		tweeningCompleted = true
	end
	didLastPointDoImmediateSwitch = false
	tween.Completed:Connect(function()
		tweeningCompleted = true
		if pointInstance.Name == tostring(lastCutscenePart) or pointInstance.ImmediateSwitch.Value == false then
			print("")
		else
			print("Switched")
			local currentPointPart = tonumber(pointInstance.Name)
			local nextPointPart = currentPointPart + 1
			local nextPointPartInstance = pointInstance.Parent:FindFirstChild(tostring(nextPointPart))
			camera.CFrame = nextPointPartInstance.CFrame
			print("camera has switched")
			didLastPointDoImmediateSwitch = true
		end
	end)
	
	repeat
		wait()
	until tweeningCompleted
end

-- Methods --
local function PlayFullCutscene()
	originalCFrame = camera.CFrame
	StarterGui:SetCore("ResetButtonCallback", false)
	local children = cutsceneParts:GetChildren()
	for i, pointPartInstance in ipairs(children) do
		cutscenePart = pointPartInstance
		count = count + 1
		if count == 1 and not doesStartAtPlayer then
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CFrame = cutsceneParts:WaitForChild("1").CFrame
		else
			fieldOfView = cutsceneParts:WaitForChild(count):WaitForChild("CameraFOV").Value
			
			PlayPartOfCutscene(camera, cutsceneParts:WaitForChild(count), fieldOfView, true)
			Character.Humanoid.WalkSpeed = 0
			Character.Humanoid.JumpPower = 0
		end
	end
	if doesStartAtPlayer then
		local tweeningTable = {
			CFrame = originalCFrame
		}
		local tweenInfoCamMovement = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local tween = TweenService:Create(camera, tweenInfoCamMovement, tweeningTable)
		tween:Play()
		local FOVTweeningTable = {
			FieldOfView = 70
		}
		local tweenInfoFov = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local tweenFov = TweenService:Create(camera, tweenInfoFov, FOVTweeningTable)
		tweenFov:Play()
		tween.Completed:Connect(function()
			endTweenComplete = true
		end)
		
		repeat
			camera.CFrame = camera.CFrame
			wait(0.001)
		until endTweenComplete
		
	end
	camera.FieldOfView = 70
	camera.CameraType = Enum.CameraType.Custom
	Character.Humanoid.WalkSpeed = 16
	Character.Humanoid.JumpPower = 50
	StarterGui:SetCore("ResetButtonCallback", true)
end

repeat
	timetaken = timetaken + 0.01
	wait()
until game:IsLoaded() == true

repeat
	wait(0.1)
until workspace:FindFirstChild(partToClickString)

repeat
	timetaken = timetaken + 0.01
	wait()
until game:IsLoaded() == true

repeat
	wait(0.1)
until #cutsceneParts:GetChildren() == script:WaitForChild("CutscenePartCount").Value

Character = Players.LocalPlayer.Character

local partToClick = workspace[partToClickString]

partToClick.Clicked:Connect(function(ClickingPart)
	if not canPlayCutscene then
		return
	end
	if ClickingPart.Parent.Name ~= Players.LocalPlayer.Name then
		return
	end
	Character.Humanoid.WalkSpeed = 0
	Character.Humanoid.JumpPower = 0
	canPlayCutscene = false
	PlayFullCutscene()
	camera.CameraType = Enum.CameraType.Custom
	camera.FieldOfView = 70
	count = 0
	wait(5)
	canPlayCutscene = true
end)
1 Like

Try doing this instead, let me know if it errors out. Make sure you have a ClickDetector in the part you want to click. Keep in mind I just edited this, there’s a few things you might no longer need in here.

local partToClick = workspace[partToClickString]

partToClick.ClickDetector.MouseClick:Connect(function(plr)
	if not canPlayCutscene then
		return
	end
	if plr.Name ~= Players.LocalPlayer.Name then
		return
	end
	Character.Humanoid.WalkSpeed = 0
	Character.Humanoid.JumpPower = 0
	canPlayCutscene = false
	PlayFullCutscene()
	camera.CameraType = Enum.CameraType.Custom
	camera.FieldOfView = 70
	count = 0
	wait(5)
	canPlayCutscene = true
end)
1 Like

I am having trouble converting the entire script, as the following part you sent me was prior to me posting my modified script:

local function cutScene()
-- your cutscene script is here or whatever you use to start it
end

-- What you're currently doing if I'm understanding correctly.
workspace.ThePartNameYouAreTouchingToActivateIt.Touched:Connect(cutScene)

-- If you wanted that to be on a ClickDetector, you'd have to add a ClickDetector to the part and do the following.
workspace.ThePartYouUsedToBeTouchingToActivateIt.ClickDetector.MouseClick:Connect(cutScene)

Ignore the first script I sent, that was just for general knowledge as I didn’t have your script before, I was just trying to showcase the changes you’d need to do to change a function from Touched to MouseClick!

In your current script, the one you sent, replace everything below partToClick with my script that I wrote for your specific use case.

1 Like
if plr.Name ~= Players.LocalPlayer.Name then

May as well compare the player instance itself.

if plr ~= Players.LocalPlayer then
3 Likes

I’m getting no errors, but it does nothing when I click the part.