I am trying to make a script in which when the right mouse button is pressed it teleports the users camera to a part called “cam”.
this is the script:
local player = game.Players.LocalPlayer
local tool = script.Parent
local userInputService = game:GetService("UserInputService")
-- Function to teleport the camera to the Cam part's position
local function teleportCamera()
local camera = game.Workspace.CurrentCamera
local camPart = tool:FindFirstChild("cam") -- Move this line inside the function
if camPart then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(camPart.Position)
end
end
-- Function to handle mouse button events
local function onInput(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then -- Right mouse button
teleportCamera()
end
end
-- Connect the function to the mouse button pressed event
userInputService.InputBegan:Connect(onInput)
the script was working before but I touched something and the next day it wouldn’t work