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 = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

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})
	script.Parent.MouseButton1Click:Connect(function()
		camera.CameraType = "Scriptable"
	end)

	return tween 
end

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



script.Parent.MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value == true then
		tween:Play()
		game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value = false
		print(game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value)	
	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
		print(game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value)
	end
end)

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.