CFrame Looking Different Direction

Hey, I want to make something like this, but it go to the different direction
https://gyazo.com/fd5ede6da13412fa31b333c9d63fe101
This is the result
And this is my code

local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = {}
		goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * -5)
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
	elseif On == true then
		On = false
		Button.Image = "rbxassetid://9133919388"
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
		wait(0.5)
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
	end
end)

Why not put the CFrame inside the goal table?
maybe something like this:
local goal = {CFrame = CFrame.New(CamSubject.Position + CamSubject.CFrame.LookVector * -5)}

So its like this right?

local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = {CFrame = CFrame.New(CamSubject.Position + CamSubject.CFrame.LookVector * -5)}
		goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.RightVector * 0) -- it's either positive 5 or negative. If that doesn't work try UpVector * 5 or negative 5
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		game.TweenService:Create(Camera, TweenInfo.new(1), goal):Play()
	elseif On == true then
		On = false
		Button.Image = "rbxassetid://9133919388"
		
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		game.TweenService:Create(Camera, TweenInfo.new(1), goal):Play()
		wait(1)
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
	end
end)

if yes then, nope

Maybe that’s what causing the issue

try a comma instead of a +

local goal = {CFrame = CFrame.New(CamSubject.Position, CamSubject.CFrame.LookVector * -5)}

Like this?

local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = {CFrame = CFrame.New(CamSubject.Position, CamSubject.CFrame.LookVector * -5)}
		goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * -5)
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
	elseif On == true then
		On = false
		Button.Image = "rbxassetid://9133919388"
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
		wait(0.5)
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
	end
end)

You should remove the

goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * -5)

line because your changing it again

1 Like

Oh ok, like this right?

local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = {CFrame = CFrame.New(CamSubject.Position, CamSubject.CFrame.LookVector * -5)}
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
	elseif On == true then
		On = false
		Button.Image = "rbxassetid://9133919388"
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
		wait(0.5)
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
	end
end)

Set goal as

CFrame.new(CamSubject.Position - Vector3.new(0, 0, 20), CamSubject.Position)

Edit:

CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * 20, CamSubject.Position)
1 Like

This?

local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * 20, CamSubject.Position)
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
	elseif On == true then
		On = false
		Button.Image = "rbxassetid://9133919388"
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
		wait(0.5)
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
	end
end)

image
Nope

Goal should be a table, not a CFrame.

1 Like

What do you mean? I dont understand

Thats what I made with this script.

local Button = script.Parent.ImageButton
local On = false
local Debounce = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame 
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	if Debounce then return end
	Debounce = true
	if On == false then
		On = true
		Button.Image = "rbxassetid://9133905664"
		player.Character.Humanoid.WalkSpeed = 0
		player.Character.Humanoid.JumpHeight = 0
		CamCFrame = Camera.CFrame
		local goal = {}
		goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * 20, CamSubject.Position)
		Camera.CameraSubject = CamSubject
		Camera.CameraType = Enum.CameraType.Scriptable
		local Tween: Tween = game.TweenService:Create(Camera, TweenInfo.new(0.5), goal)
		Tween:Play()
		Tween.Completed:Wait()
	elseif On == true then
		On = false
		player.Character.Humanoid.WalkSpeed = 16
		player.Character.Humanoid.JumpHeight = 7.2
		Button.Image = "rbxassetid://9133919388"
		local goal = {}
		goal.CFrame = CamCFrame
		Camera.CameraSubject = nil
		local Tween: Tween = game.TweenService:Create(Camera, TweenInfo.new(0.5), goal)
		Tween:Play()
		Tween.Completed:Wait()
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CameraSubject = Character.Humanoid
	end
	Debounce = false
end)

I’ve also added a debounce for script to not break.

1 Like

the goal should be a table containing the name of properties you want to change, so you would want to put your CFrame goal in between {}

1 Like

Uh, why its too far from the target?


The event camera is right here:
image

You can ajust it as you want by changing the multiplier (20).

1 Like

Ah Okay, let me try that. Thank you!