Well, I’ve been wanting to make a TweenCam that when pressing a text button changes the position of the camera to a part with the TweenService, but when clicking the text button again to return it to the humanoid but doesn’t working
local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local CurrentCamera = Workspace.CurrentCamera
local isOpen = false
script.Parent.MouseButton1Down:Connect(function()
isOpen = not isOpen
if isOpen then
CurrentCamera.CameraType = Enum.CameraType.Scriptable
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
CameraTweenStart:Play()
script.Parent.Text = "Abierto"
else
CurrentCamera.CameraType = Enum.CameraType.Scriptable
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
local CameraStartPart = {CFrame = Character:WaitForChild("Humanoid")}
local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
CameraTweenStart:Play()
CameraTweenStart.Completed:Wait()
CurrentCamera.CameraType = Enum.CameraType.Custom
script.Parent.Text = "Cerrado"
end
end)
I believe your problem is that in your second case, you don’t specify an actual CFrame:
Your target CFrame is a Humanoid Instance which will fail.
Apart from this, if both of your tweens are identical always, I’d recommend you declare the tweens outside the mouse connect listener. It is much more efficient, otherwise you are creating Tween Instances on every click .
Try changing to this and let me know if it works:
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart )
local CameraStartPart2 = {CFrame = Character:WaitForChild("HumanoidRootPart").CFrame}
local CameraTweenStart2 = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart2)
script.Parent.MouseButton1Down:Connect(function()
isOpen = not isOpen
if isOpen then
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CameraTweenStart:Play()
CameraTweenStart.Completed:Wait()
script.Parent.Text = "Abierto"
else
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CameraTweenStart2:Play()
CameraTweenStart2.Completed:Wait()
CurrentCamera.CameraType = Enum.CameraType.Custom
script.Parent.Text = "Cerrado"
end
end)
Oh okay, I think now I understood, the explanation was just not very clear. I think this is what you are looking for. Please do let me know if it works :
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart )
local cameraOffset = nil
local isOpen = false
script.Parent.MouseButton1Down:Connect(function()
isOpen = not isOpen
if isOpen then
CurrentCamera.CameraType = Enum.CameraType.Scriptable
cameraOffset = Character:WaitForChild("HumanoidRootPart").CFrame:inverse() * CurrentCamera.CFrame
CameraTweenStart:Play()
CameraTweenStart.Completed:Wait()
script.Parent.Text = "Abierto"
else
CurrentCamera.CameraType = Enum.CameraType.Scriptable
local CameraStartPart2 = {CFrame = Character:WaitForChild("HumanoidRootPart").CFrame * cameraOffset}
local CameraTweenStart2 = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart2)
CameraTweenStart2:Play()
CameraTweenStart2.Completed:Wait()
CurrentCamera.CameraType = Enum.CameraType.Custom
script.Parent.Text = "Cerrado"
end
end)
I need help with something, what you gave me I am using as a camera intro but it gives me an error invalid argument #2 (Vector3 expected, got nil)
The error is given to me on line 19
local Workspace = game:GetService("Workspace")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
local CameraTweenTwo = TweenService:Create(CurrentCamera, tweenInfo, {CFrame = Parts.TwoPart.CFrame})
local CameraTweenThree = TweenService:Create(CurrentCamera, tweenInfo, {CFrame = Parts.ThreePart.CFrame})
local cameraOffset = nil
local function CamFinish()
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
CameraTweenTwo:Play()
CameraTweenTwo.Completed:Wait()
wait(0.15)
CameraTweenThree:Play()
CameraTweenThree.Completed:Wait()
wait(0.15)
local CameraStartPart2 = {CFrame = Character:WaitForChild("HumanoidRootPart").CFrame * cameraOffset}
local CameraTweenFour= TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart2)
CameraStartPart2:Play()
CameraStartPart2.Completed:Wait()
CurrentCamera.CameraType = Enum.CameraType.Custom
end