Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Camera is not going back to players control original view after tweening?

--All scripts made by BM
local TweenService = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
flag = true
local cam = game.Workspace.Camera 
local cutsceneTime = 8
local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false, 
	0
)

function tween(part1, part2)
	while flag do
		wait(.1)
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = part1.CFrame  
		local tween = TweenService:Create(cam, tweenInfo, {CFrame = part2.CFrame})
		tween:Pause()
		script.Parent.MouseButton1Click:Connect(function()
			tween:Play()
			flag = false	
		end)
	end
end

wait(.1)
--Wait til player presses play
tween(workspace.cam1, workspace.cam2)
if flag == false then
	camToPlayer()
end

function camToPlayer()
	wait(cutsceneTime)
	cam.CameraType = Enum.CameraType.Scriptable
	player.CameraMode = Enum.CameraMode.Classic --This part doesn't work idk why
end

-I tried different variations such as cam.CameraType = Enum.CameraType.Custom in the function camToPlayer and it just won't reset to player cam control after camera tweening it just stays stationary in my workspace.cam2. Help?

2 comments

0

Format your code please.

0

Formatted now.

1 answer

The easiest way to reset the camera is:

camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = humanoid -- path to the player's character's humanoid

Try changing your script:

-- lines ~23
tween:Play()
tween.Completed:Wait()
flag = false

6 comments

0

Unfortunately does not work.

0

If I'm reading the code properly; you don't wait for the player to press the button so he can change flag to false. You tween the camera, check if flag is false - but since it isn't, the camera won't pan back. Let me edit my answer.

0

No luck I guess. The Wait() command also doesn't fire the tween:Play(). with Connect() it works and fires the tweening event but after that, it gets stuck in camera position part 2 and I can not seem to get it to go back to the players camera.

0

Well, third time's the charm. How about now?

0

All it fails to do is return to the players camera view. Everything else works fine.

0

Can you verify by a print statement, to see if the relevant lines, e.g in the if condition and in the function camToPlayer() are running?

This discussion is preserved as it was. New answers, comments, and votes are closed.