How do I make a script so if I press a part (ClickFocus), your camera will move to another part (CameraFocus) and when I click off ClickFocus, your camera will go back to your avatar?
Example (From CheckMeIn):
How do I make a script so if I press a part (ClickFocus), your camera will move to another part (CameraFocus) and when I click off ClickFocus, your camera will go back to your avatar?
Example (From CheckMeIn):
For camera focus:
For setting it back to the player:
for changing the camera’s CFrame itself, seems like that video uses TweenService
I did a script like this, but it’s not working:
local clickFocus = script.Parent
local cameraFocus = script.Parent.Parent.CameraFocus
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local clickDetector = clickFocus:WaitForChild("ClickDetector")
local isCameraFocused = false
local function focusCamera()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraFocus.CFrame
isCameraFocused = true
end
local function resetCamera()
camera.CameraType = Enum.CameraType.Custom
isCameraFocused = false
end
clickDetector.MouseClick:Connect(function()
if isCameraFocused then
resetCamera()
else
focusCamera()
end
end)
local scripts do not work in workspace, you’d have to refer to the clickdetector from a local script inside of StarterPlayerScripts (reccomended), StarterCharacterScripts, or StarterGui
local player = game:GetService("Players")
local char = nil
player.CharacterAdded:Connect(function(character)
char = character
end)
local UIS = game:GetService("UserInputService")
local mouse = player:GetMouse()
local CAMERAMODES = {}
table.insert("CAMERA_DEFAULT")
table.insert("CAMERA_CHECKINSCREEN")
local CAMERASTATES = {}
table.insert(CAMERASTATES, nil)
table.insert(CAMERASTATES, nil)
local function DefaultCamera()
local camera = workspace.CurrentCamera
if CurrentCameraMode == 2 then
if CAMERASTATES[1] ~= nil then
camera.CFrame = CAMERASTATES[1]
-- animate/tween back to where your camera was
end
end
camera.CameraType = Enum.CameraType.Custom
player.CameraMode = Enum.CameraMode.LockFirstPerson
end
local function CheckInCamera(screenpart)
local camera = workspace.CurrentCamera
player.CameraMode = Enum.CameraMode.Classic
camera.CameraType = Enum.CameraType.Scriptable
CurrentCameraMode = 2
-- animate/ tween to desired position
local offsetdistance = 5
local offsetvector = screenpart.CFrame.LookVector * offsetdistance
camera.CFrame = CFrame.new(screenpart.CFrame.Position + offsetvector,
screenpart.CFrame.Position)
end
local CAMERAFUNCTIONS = {}
table.insert(CAMERAFUNCTIONS, DefaultCamera)
table.insert(CAMERAFUNCTIONS, CheckInCamera)
local function onInputBegan(input, proc)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if CurrentCameraMode == 2 then
if mouse.target ~= CheckInScreenPart then
CAMERAFUNCTIONS[1]()
CurrentCameraMode = 1
end
end
end
end
local CheckInScreenPart = workspace.wherever.it.is
local ClickD = CheckInScreenPart.ClickDetector
ClickD.MouseClick:Connect(function(player)
if CurrentCameraMode == 1 then
local camera = workspace.CurrentCamera
CAMERASTATES[1] = camera.CFrame
CAMERAFUNCTIONS[2](CheckInScreenPart)
end)
UIS.InputBegan:Connect(onInputBegan)
I have this LocalScript in StarterPlayerScripts
Assign any ClickDetectors in the same script to work like this