Cutscence inside while loop not working! NEED HELP ASAP!

Hello Developers,

I’m here to fix my camera code in my game. So basically when I run the script the while loop in the script work fine but the tween in it is not tweening for some reason. My goal is to make the cutscence in the while loop work. Any help would be appreciate by me.

Note: The IsRunningLoop value is true when the script run and it didn’t got set to false in other script.

Code:

--- // Services // ---

local Service_Players = game:GetService('Players')
local Service_Workspace = game:GetService('Workspace')
local Service_TweenService = game:GetService('TweenService')
local Service_ReplicatedStorage = game:GetService('ReplicatedStorage')

--- // GUI Objects // ---

local TransitionFrame = script.Parent:WaitForChild('TransitionFrame')

--- // Player & Camera Variables // ---

local Player = Service_Players.LocalPlayer

local PlayerCamera = Service_Workspace.CurrentCamera
local PlayerMouse = Player:GetMouse()

local CameraFolder = Service_Workspace:WaitForChild('Cutscence_Cameras')
local MainCamera = nil

--- // Boolean, String, Number, Values, and Table Variables // ---

-- < Tables > --

local CutscenceCameraOrders = {
	CameraFolder:WaitForChild('AzraLoadingCamera1');
	CameraFolder:WaitForChild('AzraLoadingCamera2');
	CameraFolder:WaitForChild('AzraLoadingCamera3');
	CameraFolder:WaitForChild('AzraLoadingCamera4');
	CameraFolder:WaitForChild('AzraLoadingCamera5');
}

-- < Booleans & Boolean Values > --

local IsRunningLoop = Service_ReplicatedStorage:WaitForChild('LoopController')

-- < Numbers & Number Values > --

local CameraIndex = 1
local CutscenceSpeed = 20
local CameraDelayMovement = 0.05
local MaxTilt = 20
local TransitionSpeed = 1

--- // Infos // ---

local TransitionInfo = TweenInfo.new(
	TransitionSpeed,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)

--- // Tweens // ---

local TransitionStart = Service_TweenService:Create(TransitionFrame, TransitionInfo, {BackgroundTransparency = 0})
local TransitionEnd = Service_TweenService:Create(TransitionFrame, TransitionInfo, {BackgroundTransparency = 1})

--- // Functions & Events // ---

repeat task.wait()
	PlayerCamera.CameraType = Enum.CameraType.Scriptable
until PlayerCamera.CameraType == Enum.CameraType.Scriptable

PlayerCamera.CFrame = CutscenceCameraOrders[1].CFrame

local function RunTransition(TransitionState: string)
	local FilteredTransitionState = string.lower(TransitionState)

	if FilteredTransitionState == 'start' then
		TransitionStart:Play()
		task.wait(TransitionInfo.Time)
	elseif FilteredTransitionState == 'end' then
		TransitionEnd:Play()
		task.wait(TransitionInfo.Time)
	elseif FilteredTransitionState == 'both' then
		TransitionStart:Play()
		task.wait(TransitionInfo.Time)
		TransitionEnd:Play()
		task.wait(TransitionInfo.Time)
	end
end

coroutine.resume(coroutine.create(function()
	while IsRunningLoop.Value == true do
		if CameraIndex >= #CutscenceCameraOrders then
			CameraIndex = 0
		end
		
		CameraIndex += 1
		MainCamera = CutscenceCameraOrders[CameraIndex]
		local CutscenceTrack = Service_TweenService:Create(PlayerCamera, TweenInfo.new(CutscenceSpeed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0), {CFrame = MainCamera.CFrame})
		CutscenceTrack:Play()
		task.wait(CutscenceTrack.TweenInfo.Time)
		RunTransition('both')
	end
end))

game:GetService("RunService").RenderStepped:Connect(function()
	if IsRunningLoop.Value == false then return end
	Service_TweenService:Create(PlayerCamera, TweenInfo.new(CameraDelayMovement, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0), {CFrame = MainCamera.CFrame * CFrame.Angles(math.rad((((PlayerMouse.Y - PlayerMouse.ViewSizeY / 2) / PlayerMouse.ViewSizeY)) * -MaxTilt),math.rad((((PlayerMouse.X - PlayerMouse.ViewSizeX / 2) / PlayerMouse.ViewSizeX)) * -MaxTilt),0)}):Play()
end)
2 Likes

I really need this code to be fix, whoever trying to help me will be appreciate a lot by me. Thanks for your time!!

2 Likes