Fnaf Look Left and Right System

I’m trying to loop the CFrame by Rotating and using button but it doesn’t loop right
If I go right then go left it wont go to the middle but just go to the left
I researched how to do CFrames by using the wiki and by reading post but it doesn’t help me

Im trying to make this:

I figured out the problem, here’s the script i made for people who need help

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local Part = game.Workspace.Office1Focus
local TweenService = game:GetService(“TweenService”)
local LeftArrow = script.Parent.LeftTurn
local RightArrow = script.Parent.RightTurn

local tween = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(-90), 0),
Focus = Part.CFrame
}
)

local tween2 = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(0), 0),
Focus = Part.CFrame
}
)

local tween3 = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(90), 0),
Focus = Part.CFrame
}
)

local Looking = 0

enabled = true

RightArrow.MouseEnter:Connect(function()
print(enabled)
if not enabled then
return
end

print(enabled)
enabled = false

if Looking == -1 or Looking == -2 then
	tween2:Play()
	-- cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
	LeftArrow.Visible = true
	Looking = 0
	wait(0.5)  enabled = true print(enabled)
else
	
	
	Looking = Looking + 1
	tween:Play()
	--cam:Interpolate(Part.CFrame,Part.CFrame * CFrame.Angles(0,  math.rad(-90), 0),5)
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(-90), 0)
	RightArrow.Visible = false
	wait(0.5)  enabled = true print(enabled)

	print(Looking)
end

end)

LeftArrow.MouseEnter:Connect(function()
print(enabled)
if not enabled then
return
end
enabled = false
print(enabled)
if Looking == 1 or Looking == 2 then

	tween2:Play()
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
	RightArrow.Visible = true
	Looking = 0
	wait(0.5)  enabled = true print(enabled)
else

	Looking = Looking - 1
	tween3:Play()
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(90), 0)
	LeftArrow.Visible = false
	wait(0.5)  enabled = true print(enabled)

	print(Looking)

end

end)

3 Likes

Properly formatted code because it’s too hard to read

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local cam = workspace.CurrentCamera
local Part = game.Workspace.Office1Focus

local LeftArrow = script.Parent.LeftTurn
local RightArrow = script.Parent.RightTurn

local Around = 1
local LookedRight = false
local LookedLeft = false
local LookedMiddle = true

local Looking = 0

RightArrow.MouseButton1Click:Connect(function()
if Looking == 2 then – max
cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(-90), 0)
Looking = 1 – Default
else
if Looking == 1 then
cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
Looking = Looking + 1

	else if Looking == -1 or Looking == -2 then
			cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
			Looking = 2
		else
		Looking = Looking + 1
			cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(-90), 0)
		end
	end
	
	print(Looking)
end
wait(1)
end)

LeftArrow.MouseButton1Click:Connect(function()
if Looking == -2 then – max
cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(90), 0)
Looking = -1 – Default
else
if Looking == -1 then
cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
Looking = Looking - 1
	else if Looking == 1 or Looking == 2 then
			cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
			Looking = -2
		else
			Looking = Looking - 1
			cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(90), 0)
		end
	end

	print(Looking)
end
wait(1)
end)
2 Likes

yeah my code was a mess lol but i sorted it:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local Part = game.Workspace.Office1Focus
local TweenService = game:GetService(“TweenService”)
local LeftArrow = script.Parent.LeftTurn
local RightArrow = script.Parent.RightTurn

local tween = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(-90), 0),
Focus = Part.CFrame
}
)

local tween2 = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(0), 0),
Focus = Part.CFrame
}
)

local tween3 = TweenService:Create(
cam,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, math.rad(90), 0),
Focus = Part.CFrame
}
)

local Looking = 0

enabled = true

RightArrow.MouseEnter:Connect(function()
print(enabled)
if not enabled then
return
end


print(enabled)
enabled = false

if Looking == -1 or Looking == -2 then
	tween2:Play()
	-- cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
	LeftArrow.Visible = true
	Looking = 0
	wait(0.5)  enabled = true print(enabled)
else
	
	
	Looking = Looking + 1
	tween:Play()
	--cam:Interpolate(Part.CFrame,Part.CFrame * CFrame.Angles(0,  math.rad(-90), 0),5)
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(-90), 0)
	RightArrow.Visible = false
	wait(0.5)  enabled = true print(enabled)

	print(Looking)
end


end)

LeftArrow.MouseEnter:Connect(function()
print(enabled)
if not enabled then
return
end
enabled = false
print(enabled)
if Looking == 1 or Looking == 2 then


	tween2:Play()
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0, 0, 0)
	RightArrow.Visible = true
	Looking = 0
	wait(0.5)  enabled = true print(enabled)
else

	Looking = Looking - 1
	tween3:Play()
	--cam.CFrame = workspace.Office1Focus.CFrame * CFrame.Angles(0,  math.rad(90), 0)
	LeftArrow.Visible = false
	wait(0.5)  enabled = true print(enabled)

	print(Looking)

end


end)
2 Likes