How do i stop this cutscene from looping

I was looking through youtube to find a script to make a cutscene using moon animator I followed his instructions and it works fine, the only problem I have is it keeps looping after it’s finished, what i want to do is let it play ONCE everytime you join, or respawn.

Serverscriptservice script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local Remote  :RemoteEvent = game.ReplicatedStorage.CutsceneRemote
		while true do
			task.wait(5)
			local Remote : RemoteEvent = game.ReplicatedStorage.CutsceneRemote
			local CutsceneFolder :Folder = game.ReplicatedStorage.spawncut
			Remote:FireClient(Player, Player.Character.HumanoidRootPart, CutsceneFolder)
			
		end
	end)
end)

StarterCharacterScripts script:

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

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

local PlayerGui = LocalPlayer.PlayerGui
local Camera = workspace.CurrentCamera

local Remote = RS:FindFirstChild("CutsceneRemote") --/Change this to your destination of the remote

function Cinematic(Target, Folder)
	local CinematicsFolder = Folder

	local CurrentCameraCFrame = workspace.CurrentCamera.CFrame

	Camera.CameraType = Enum.CameraType.Scriptable
	local FrameTime = 0
	local Connection

	Connection = RunService.RenderStepped:Connect(function(DT)
		local NewDT = DT * 60
		FrameTime += NewDT
		local NeededFrame = CinematicsFolder.Frames:FindFirstChild(tonumber(math.ceil(FrameTime)))
		local NeededFOV = CinematicsFolder.FOV:FindFirstChild(tonumber(math.ceil(FrameTime)))
		if NeededFrame then
			Character.Humanoid.AutoRotate = false
			game.StarterGui:SetCore("ResetButtonCallback", false)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
			Camera.CFrame = Target.CFrame * NeededFrame.Value
			print("on")
			if NeededFOV then
				Camera.FieldOfView = tonumber(NeededFOV.Value)
			end	
		else
			Connection:Disconnect()
			Connection = nil
			game.StarterGui:SetCore("ResetButtonCallback", true)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
			Character.Humanoid.AutoRotate = true
			Camera.CameraType = Enum.CameraType.Custom
			Camera.CFrame = CurrentCameraCFrame	
			Camera.FieldOfView = 70
			print("off")
		end
		
		Character.Humanoid.Died:Connect(function()
			Connection:Disconnect()
			Connection = nil
			game.StarterGui:SetCore("ResetButtonCallback", true)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
			Character.Humanoid.AutoRotate = true
			Camera.CameraType = Enum.CameraType.Custom
			Camera.CFrame = CurrentCameraCFrame	
			Camera.FieldOfView = 70
			print("off")
		end)
	end)
end

Remote.OnClientEvent:Connect(function(HumRP, Folder)
	Cinematic(HumRP, Folder)
end)

can you send the output please

If you can provide a video fo the issue, it could make finding the problem much easier However, I’m pretty sure it is because you have a while loop in the ServerScriptService which basically means that you are indefinitely Firing the RemoteEvent once a player Joins. If you only want it to be fired once (Play once as soon as player spawns), I would suggest removing the while loop.

remove the while loop in the server script

Try to change this to ServerScriptService script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local Remote  :RemoteEvent = game.ReplicatedStorage.CutsceneRemote
			task.wait(5) -- you can also remove this if you want it to play from the start and not after 5 secs
			local Remote : RemoteEvent = game.ReplicatedStorage.CutsceneRemote
			local CutsceneFolder :Folder = game.ReplicatedStorage.spawncut
			Remote:FireClient(Player, Player.Character.HumanoidRootPart, CutsceneFolder)
	end)
end)

Also @RafehPvP and @Kurookku say truth. I just made it in case if you don’t understand.

1 Like