My Cameras CFrame goes from part 1 cframe to part three cframe. For Loop is skiping over index 2

A quick rundown is whenever the text is done displaying on the GUI i want to switch the cameras CFrame which is why I have the line wait( Text_Display_Time) to not only display the next line of text but switch the scene. Im using parts for my scenes and have them tagged However, my cameras cframe is going from index 1 - 3 and completely skipping over my 2nd cutscene part

local function animateText()
	currentTextIndex = (prevTextIndex % #TEXTS) + 1
	prevTextIndex = currentTextIndex

	local newText = TEXTS[currentTextIndex]
	local textLabelSize = TextLabel.TextBounds
	local textTweenIn = TweenService:Create(TextLabel, TweenInfo.new(1), {
		TextTransparency = 0,
		Size = UDim2.new(0, 586, 0, 98)
	})
	local textTweenOut = TweenService:Create(TextLabel, TweenInfo.new(1), {
		TextTransparency = 1,
		Size = UDim2.new(0, 586, 0, 98)
	})
	
	

	textTweenOut.Completed:Connect(function()
		currentText = newText
		TextLabel.Text = currentText
		textTweenIn:Play()
	end)
	textTweenIn:Play()

	local currentCharacterIndex = 0
	while currentCharacterIndex < #newText do
		currentCharacterIndex = currentCharacterIndex + 1
		TextLabel.Text = newText:sub(1, currentCharacterIndex)
		wait(0.05)
	end

	wait(TEXT_DISPLAY_TIME)
	textTweenOut:Play()
	
local CameraIndex = 1

for i, CameraPart in ipairs(CameraParts) do
    if CameraPart == CameraPart then
        CameraIndex = i
        break
    end
end

if CameraIndex < #CameraParts then
    CameraIndex = CameraIndex + 1
else
    CameraIndex = 1
end

CameraPart = CameraParts[CameraIndex]
	Camera.CFrame = CameraPart.CFrame

end


local t0 = os.clock()
while os.clock() - t0 < CUTSCENE_LENGTH do
	animateText()
	RunService.Stepped:Wait()
end

It looks like you are trying to switch the camera CFrame in your script after a certain amount of time. If I understand correctly, you want to switch between different cutscene parts, but the camera is skipping over the second cutscene part, and it is not working as expected.

First, you need to make sure that the CameraPart is a valid object in the CameraParts array. To do this, you should print out the CameraParts array to check that all the required parts have been tagged appropriately.
It looks like you are trying to switch the camera CFrame in your script after a certain amount of time. If I understand correctly, you want to switch between different cutscene parts, but the camera is skipping over the second cutscene part, and it is not working as expected.

First, you need to make sure that the CameraPart is a valid object in the CameraParts array. To do this, you should print out the CameraParts array to check that all the required parts have been tagged appropriately.

if CameraPart == CameraPart then

to:

if CameraPart.Name == "CutscenePart2" then

This will make sure that the correct part is being selected before setting the CFrame.

If this does not fix the problem, you can try adding a print statement inside the for loop to see the index of the CameraPart that is being selected, like this:

for i, CameraPart in ipairs(CameraParts) do
    print(i, CameraPart.Name)
    if CameraPart == CameraPart then
        CameraIndex = i
        break
    end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.