For loop/coroutine won't stop, player's camera stays on airplane

I have a plane in the sky that the player’s camera switches to while moving, using a for loop for every wait() to keep the players camera on the plane using the track type of camera.

When I call break in an if statement if a value is true and set the player’s camera back to the custom ROBLOX camera, it stays on the plane camera.

I’ve tried using break and coroutine.yield(), but both won’t work (I’ve also kept a little bit of extra script besides the function)

Any help would be appreciated, thank you!

NOTE: this is a client-sided script inside of the player’s playergui.

	camera.CameraType = Enum.CameraType.Track
	for i = 1,3000 do
		camera.CameraSubject = workspace.CameraForAirplane
		if playerJumepdValue == true then
			game.ReplicatedStorage.PlayerJumpedOut:FireServer()
			wait(0.01)
			coroutine.yield() -- I tried using both the yield coroutine and break, but both won't work.
			break
		end
		wait()
	end
end)

local FirstTween = TweenService:Create(camera	, TweenInfo.new(0.6), {["CFrame"] = player.Character:WaitForChild("Head").CFrame})

game.ReplicatedStorage.gameStartingBell.OnClientEvent:Connect(function()
	script.sounds.bell.Volume = 2
	wait()
	script.sounds.bell:Play()
	maintext.Text = "Round Starting..."
	local fadeFrame = frame.Parent.fadeFrame
	fadeFrame.BackgroundTransparency = 1
	fadeFrame.Visible = true
	for i = 1,50 do
		fadeFrame.BackgroundTransparency-=0.02
		wait(0.01)
	end
	coroutine.resume(planeMoveCamera)
	maintext.Parent.Visible = false --(this is the main frame)
	wait(1)
	for i = 1,50 do
		fadeFrame.BackgroundTransparency+=0.02
		wait(0.01)
	end
	wait(1.5)
	jumpButton:TweenPosition(UDim2.new(0.446, 0,0.807, 0),"InOut","Sine" ,0.4)
	--{0.446, 0},{1.2, 0} tween when off camera position
	--press jumpButtonFunction
	
	jumpButton.MouseButton1Click:Connect(function()
		jumpButton:TweenPosition(UDim2.new(0.446, 0,1.2, 0),"InOut","Sine" ,0.4)
		jumpButton.Sound:Play()
		player.Character.HumanoidRootPart.CFrame = workspace.airplaneStart.CFrame
		controls:Enable()
		FirstTween:Play()
		player.Character.HumanoidRootPart.Anchored = false
		playerJumepdValue.Value = true
		wait(.6)
		camera.CameraType = Enum.CameraType.Custom -- this changes player's camera back to normal, but it won't because the forloop wont stop when I break/yield it.
	end)
	
end)
3 Likes

It’s been a long time and you have probably found the solution to this but just so you know CameraSubject works on all camera mods and not just scriptable. You’ll have to change CameraSubject to the character after the cutscene.

4 Likes

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