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)