Camera does not focus back to the player

I have a function that switches the player’s camera to target a part if you press a gui button. But only switches to the part if a value is true and turns it to false. And if you press it again while it is false it makes the value true and targets back to the player. Problem is the camera does not go back to the player after it gets pressed. It targets the part but doesn’t go back to the player. I have not been able to fix it or seen any other posts that can really fix my issue. Localscript in startergui. Any help is appreciated.

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local cutsceneTime = 0.25
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local plrname = player.Name

local tweenInfo =

function tweenFun (part1,part2, part3, part4, part6)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	camera.CFrame = part2.CFrame

	local tween = TweenService:Create(camera, tweenInfo,  {CFrame = part4.CFrame})
		camera.CameraType = "Scriptable"

	return tween 

local tween  = tweenFun(workspace.Test1, workspace.Test2, workspace.Test3, workspace.Test4)

	if game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value == true then
		game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value = false
	elseif game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value == false then
		game.Workspace.CurrentCamera.CameraType = "Custom"
		camera.CameraType = Enum.CameraType.Custom
		game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
		game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value = true

In the tweenFun() function, you connected a function to script.Parent.MouseButton1Click that sets the camera type to scriptable every time. Is it necessary for what you want to do?

1 Like

Oh wow. I didn’t see that. Well, now that you mentioned it I thought of it more and realized that was the issue. Thanks for telling me. But now whenever It goes to focus on the part after it finishes it goes straight back to focus on the player. Any solutions?

You could try putting camera.CameraType = Enum.CameraType.Scriptable right before tween:Play() instead. I see that it is on the first line of tweenFun(), but tweenFun() is called before you click the button so the camera type should be changed right before you play the tween.

1 Like

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