I need help with a cutscene, it doesn't stop playing

Hello there, I am having an issue with a cutscene that is supposed to play when you join the game, which it does. I want it to keep playing the cutscene until they push play. The problem is that it doesn’t stop once they push play, the cam goes back to the character but doesn’t stay, it goes back to the tweening.

Here is the cutscene script:

local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"

ContextActionService:BindAction(
    FREEZE_ACTION,
    function() return Enum.ContextActionResult.Sink end,
    false,
    unpack(Enum.PlayerActions:GetEnumItems())
)

local TweenService = game:GetService("TweenService")
local Camera = game.Workspace.CurrentCamera

local function MoveCamera(StartPart, EndPart, Duration, EasingStyle, EasingDirection)
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = StartPart.CFrame
	local Cutscene = TweenService:Create(Camera, TweenInfo.new(Duration, EasingStyle, EasingDirection), {CFrame = EndPart.CFrame})
	Cutscene:Play()
	wait(Duration)
end

function Cutscene()
	if script.disablecam.Value == false then
		MoveCamera(game.Workspace.location0, game.Workspace.location1, 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		wait(5)
		MoveCamera(game.Workspace.location1, game.Workspace.location2, 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		wait(5)
		MoveCamera(game.Workspace.location2, game.Workspace.location3, 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		wait(5)
		MoveCamera(game.Workspace.location3, game.Workspace.location0, 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		wait(5)
	end
end

while true do
	if script.disablecam.Value == false then
		Cutscene()
	else
		script:Destroy()
		break
	end
end

Here is the play button script:

local Camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Click:Play()
	
	script.Parent.Parent.Parent.tutorialFrame:TweenPosition(UDim2.new(0.6,0,1.5,0),"Out","Quad",0.5,true)
	script.Parent.Parent:TweenPosition(UDim2.new(-1.5, 0,0.5, 0),"Out","Quad",1,true)
	
	for i = 1, 10 do
		wait(0.05)
		script.Parent.Parent.Parent.BackgroundTransparency = script.Parent.Parent.Parent.BackgroundTransparency - 0.10
	end
	
	
	script.Parent.Parent.Parent.Parent.moveCam.disablecam.Value = true
	
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
	
	local ContextActionService = game:GetService("ContextActionService")
	local FREEZE_ACTION = "freezeMovement"
	ContextActionService:UnbindAction(FREEZE_ACTION)
	
	wait(1)
	
	for i = 1, 10 do
		wait(0.05)
		script.Parent.Parent.Parent.BackgroundTransparency = script.Parent.Parent.Parent.BackgroundTransparency + 0.10
	end
	for _, gui in ipairs(game.Players.LocalPlayer.PlayerGui:GetChildren())do
		if gui.Name ~= "LoadScreen" and gui:IsA("ScreenGui") then
			gui.Enabled = true
		elseif gui.Name == "LoadScreen" and gui:IsA("ScreenGui") then
			gui.Enabled = false
		end
	end
	game.Players.LocalPlayer.PlayerGui:FindFirstChild("checkAlive").Disabled = false
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,true)
	game.ReplicatedStorage.Remotes.Loaded:FireServer()
end)

Any help would be appreciated. :slightly_smiling_face:

2 Likes

you didn’t set

script.disablecam.Value

to false, so it is just in an infinite loop

Yes I did, its in another script I forgot to include, its the first script to set this process in motion.

script.Parent.moveCam.disablecam.Value = false

i don’t know then, code looks fine to me

Anyone able to help, I haven’t solved this issue yet.

You can’t destroy script by same script
Destroy a script parent or create a new bindable event and destroy it via another script.

Also replace while true do with while wait() do to prevent lags.

To me it looks like it will continue to play until the cutscene has gone through the loop, then it’ll stop. Is this the problem that you are facing? You want it to stop as soon as it is switched to true?

Yes, that’s what I’m trying to do.

The reason that this is happening is because your script yields due to the wait()s (Looks like a total of 40 seconds) before it checks the value again.

I would propose using a :GetPropertyChangedSignal event to detect changes in the value.

This way every time the script’s value is changed it will immediately detect the change and you can run code to stop the cutscene.

script.disablecam:GetPropertyChangedSignal("Value"):Connect(function()
      if script.disablecam.Value == true then
           Cutscene:Cancel()
      end
end)

Problem 1 The current tween is going to finish after changing the value.

You to stop the Tween as it’s going you can use Tween:Cancel()
however you will need to be able to reference the current tween at all times.
Put

local Cutscene 

At the beginning of your script and remove the local infront of the one inside the MoveCamera function. Then drop Tween:Cancel() inside our GetPropertyChangedSignal function.

Problem 2 Any tweens set to happen in the future are going to start up after.

You can easily fix this by running

if script.disablecam.Value == false then

right before

Cutscene:Play()

Hope this helps!

1 Like

I’m quite new to scripting, but I thought I might try to help. Aren’t you doing an infinite loop here? Also, if it’s true that you can’t “script:Destroy()” from the same script, then you’re just infinitely looping it. Cause the “else” can be true, but if it can’t do what you’re asking, it’ll just keep looping the if statement, disregarding the "else. I could be looking at it wrong though.

If this is the case, you’d want to find another way to stop your script instead of Destroy(), so that it doesn’t keep looping.

function Cutscene()
  for i = 1, 4 do
     if not script.disablecam.Value == false then break end
   
   
  MoveCamera(game.Workspace:WaitForChild('location' .. tostring(i - 1)), game.Workspace:WaitForChild('location' .. tostring(i), 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
   wait(5)
  end	 
 end)

script.disablecam:GetPropertyChangedSignal('Value'):Connect(function(x)
 if not x then
  Cutscene()
 else
  script.Disabled = true -- You can't destroy script by same script
end)

edited on phone so sorry for this

You can give this script a try:

wait(5)
MoveCamera(game.Workspace.location3, game.Workspace.location0, 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) -- Begins Cutscene
wait(5)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") -- Returns camera back to player

Edit: Since you are waiting for a player to push play you can also use this script below.

while true do
	if script.disablecam.Value == false then
		Cutscene() -- Plays cutscene
	else
		Camera.CameraType = Enum.CameraType.Custom
        Camera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") -- Returns camera back to player
	end
end