Irritating Cutscene Issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a cutscene for the end of a chase in my indie horror game.

  2. What is the issue? Include screenshots / videos if possible!
    My code seems fine, but it isn’t playing the animations.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, and asked multiple different ais to review my code.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Script One, Server Script which is triggered by a part touch.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Event = ReplicatedStorage.Remotes:WaitForChild("ChasePhaseTwo")
local DisableEvent = ReplicatedStorage.Remotes:WaitForChild("DisableControls")
local EnableEvent = ReplicatedStorage.Remotes:WaitForChild("EnableControls")

local debounce = {}

script.Parent.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)

	if player and character:FindFirstChild("Humanoid") and not debounce[player] then
		debounce[player] = true
		print("Server: Player " .. player.Name .. " triggered ChasePhaseTwo")

		-- Disable controls and trigger cutscene
		DisableEvent:FireClient(player)
		print("Server: Fired DisableEvent for " .. player.Name)
		Event:FireAllClients()
		print("Server: Fired ChasePhaseTwo event for all clients")

		-- Wait for cutscene duration (adjust to match animation length)
		task.wait(6.5)
		print("Server: Cutscene wait complete, teleporting player")

		-- Teleport player to EndChaseTeleportPosition
		local teleportTarget = workspace:WaitForChild("EndChaseTeleportPosition", 10)
		if teleportTarget then
			character:MoveTo(teleportTarget.Position + Vector3.new(0, 2, 0))
			print("Server: Teleported " .. player.Name .. " to EndChaseTeleportPosition")
		else
			warn("Server: EndChaseTeleportPosition not found in Workspace after waiting")
		end

		-- Re-enable controls
		EnableEvent:FireClient(player)
		print("Server: Fired EnableEvent for " .. player.Name)

		-- Clear debounce
		task.wait(2)
		debounce[player] = nil
		print("Server: Debounce cleared for " .. player.Name)
	end
end)

Script Two, LocalScript in StarterPlayerScripts

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ContentProvider = game:GetService("ContentProvider")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local Event = ReplicatedStorage.Remotes:WaitForChild("ChasePhaseTwo")
local Characters = ReplicatedStorage:WaitForChild("EndChaseAnimation")
local John = Characters:WaitForChild("NaughtyJohn")
local Main = Characters:WaitForChild("PlayerModel")

local ChaseTriggerer = workspace:WaitForChild("ObjectiveParts"):WaitForChild("ChasePhaseTwo")

-- Utility: Disable collisions
local function disableCollisions(model)
	if not model then
		warn("Client: No model provided for disableCollisions")
		return
	end
	for _, part in ipairs(model:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CanCollide = false
		end
	end
end

-- Make player invisible/visible
local function setPlayerVisible(character, isVisible)
	if not character then
		warn("Client: No character found for visibility toggle")
		return
	end
	print("Client: Setting player visibility to " .. tostring(isVisible))
	for _, part in ipairs(character:GetDescendants()) do
		if part:IsA("BasePart") or part:IsA("Decal") then
			part.Transparency = isVisible and 0 or 1
		elseif part:IsA("Accessory") and part:FindFirstChild("Handle") then
			part.Handle.Transparency = isVisible and 0 or 1
		elseif part:IsA("ParticleEmitter") then
			part.Enabled = isVisible
		end
	end
end

-- Preload cutscene assets
local function preloadCharacters()
	print("Client: Preloading cutscene assets")
	local assets = {}
	for _, desc in ipairs(Characters:GetDescendants()) do
		if desc:IsA("MeshPart") or desc:IsA("Decal") or desc:IsA("Texture") or desc:IsA("Animation") then
			table.insert(assets, desc)
		end
	end
	ContentProvider:PreloadAsync(assets)
	print("Client: Asset preloading complete")
end

Event.OnClientEvent:Connect(function()
	print("Client: Received ChasePhaseTwo event")
	local success, err = pcall(function()
		-- Validate character
		local character = player.Character or player.CharacterAdded:Wait()
		if not character then
			warn("Client: Player character not found")
			return
		end
		print("Client: Player character found")

		-- Wait for game to load
		game.Loaded:Wait()
		print("Client: Game loaded, proceeding with cutscene setup")

		-- Validate MainAnimationStartPoint
		local targetCFrame = workspace:WaitForChild("MainAnimationStartPoint", 10)
		if not targetCFrame then
			warn("Client: MainAnimationStartPoint not found in Workspace after waiting")
			return
		end
		print("Client: Found MainAnimationStartPoint")

		-- Hide player
		setPlayerVisible(character, false)

		-- Preload assets and force streaming
		preloadCharacters()
		player:RequestStreamAroundAsync(targetCFrame.Position, 1)
		task.wait(1)
		print("Client: Streaming requested and assets preloaded")

		-- Move cutscene models to workspace
		Characters.Parent = workspace
		if ChaseTriggerer then
			ChaseTriggerer:Destroy()
			print("Client: ChaseTriggerer destroyed")
		end

		-- Validate model structure
		local mainPrimary = Main:FindFirstChild("PrimaryPart")
		local johnPrimary = John:FindFirstChild("PrimaryPart")
		if not mainPrimary or not johnPrimary then
			warn("Client: PrimaryPart missing on Main or John")
			return
		end
		print("Client: PrimaryParts found for Main and John")

		-- Reposition John relative to PlayerModel
		local offsetCFrame = mainPrimary.CFrame:ToObjectSpace(johnPrimary.CFrame)
		Main:PivotTo(targetCFrame.CFrame)
		John:PivotTo(mainPrimary.CFrame * offsetCFrame)
		print("Client: Repositioned Main and John models")

		-- Disable collisions
		disableCollisions(John)
		print("Client: Disabled collisions for John")

		-- Load animations
		local JohnAnim = script:WaitForChild("John", 5)
		local MainAnim = script:WaitForChild("Player", 5)
		if not JohnAnim or not MainAnim then
			warn("Client: Failed to find John or Player animation in script")
			return
		end
		print("Client: Found John and Player animations")

		-- Validate humanoids
		local JohnHumanoid = John:WaitForChild("Humanoid", 5)
		local MainHumanoid = Main:WaitForChild("Humanoid", 5)
		if not JohnHumanoid or not MainHumanoid then
			warn("Client: Humanoid missing in John or Main")
			return
		end
		print("Client: Found Humanoids for John and Main")

		-- Load animation tracks
		local JohnAnimTrack = JohnHumanoid:LoadAnimation(JohnAnim)
		local MainAnimTrack = MainHumanoid:LoadAnimation(MainAnim)
		if not JohnAnimTrack or not MainAnimTrack then
			warn("Client: Failed to load animation tracks")
			return
		end
		print("Client: Loaded animation tracks")

		JohnAnimTrack.Priority = Enum.AnimationPriority.Movement
		MainAnimTrack.Priority = Enum.AnimationPriority.Movement

		-- Set up camera
		local torso = Main:WaitForChild("Torso", 5)
		if not torso then
			warn("Client: Torso not found in Main")
			return
		end
		camera.CameraSubject = torso
		camera.CameraType = Enum.CameraType.Custom
		camera.CFrame = camera.CFrame * CFrame.new(0, 5, -10)
		print("Client: Camera set up for cutscene")

		-- Play animations
		JohnAnimTrack:Play()
		MainAnimTrack:Play()
		print("Client: Playing John and Main animations")

		-- Handle animation end
		MainAnimTrack.Ended:Connect(function()
			print("Client: Main animation ended")
			-- Reset camera
			if player.Character and player.Character:FindFirstChild("Head") then
				camera.CameraSubject = player.Character.Head
			end
			camera.CameraType = Enum.CameraType.Custom
			print("Client: Camera reset to player head")

			-- Show player again
			setPlayerVisible(player.Character, true)
			print("Client: Player visibility restored")
		end)
	end)

	if not success then
		warn("Client: Error in ChasePhaseTwo handler: " .. tostring(err))
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

first thing to do is to change the animation priority to action4

besides, why are you changing the priority at runtime?

1 Like

we lost the animation file, so we cannot edit it anymore.

i’m confused, because all the prints are firing, but i cant see it.

Server: Player superman978705 triggered ChasePhaseTwo  -  Server - PhaseTwoStarter:16
  06:57:38.178  Server: Fired DisableEvent for superman978705  -  Server - PhaseTwoStarter:20
  06:57:38.179  Server: Fired ChasePhaseTwo event for all clients  -  Server - PhaseTwoStarter:22
  06:57:38.231  Client: Received ChasePhaseTwo event  -  Client - PhaseTwoHandler:61
  06:57:38.232  Client: Player character found  -  Client - PhaseTwoHandler:69
  06:57:44.687  Server: Cutscene wait complete, teleporting player  -  Server - PhaseTwoStarter:26
  06:57:44.689  Server: Teleported superman978705 to EndChaseTeleportPosition  -  Server - PhaseTwoStarter:32
  06:57:44.689  Server: Fired EnableEvent for superman978705  -  Server - PhaseTwoStarter:39
  06:57:46.698  Server: Debounce cleared for superman978705  -  Server - PhaseTwoStarter:44