I changed the CFrame of the player’s camera and I have a ClickDetector on a part, but it won’t detect. I have tried multiple solutions on the developer forum but none of them seem to work. Could somebody help me?
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local clickPart = game.Workspace:WaitForChild("Part")
local clickdetector = game.Workspace.clickPart.ClickDetector
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Primary = Char:WaitForChild("HumanoidRootPart")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local camPos = camera.CFrame.Position
local Cam = workspace.CurrentCamera
local StudsY = 20
local function Enable()
Cam.CameraType = Enum.CameraType.Scriptable
game["Run Service"].RenderStepped:Connect(function()
Cam.CFrame = game.Workspace.CamPart.CFrame
if clickdetector.MouseClick == true then
Cam.CFrame = CFrame.new(Primary.Position + Primary.CFrame.UpVector*StudsY) * CFrame.Angles(math.rad(-90),0,0)
end
end)
end
Enable()
``
-- Services
local run = game:GetService("RunService")
local players = game:GetService("Players")
-- Objects
local clickPart = workspace:WaitForChild("Part") :: BasePart
local clickDetector = clickPart:WaitForChild("ClickDetector") :: ClickDetector
-- Player & Charcater
local player = players.LocalPlayer
local camera = workspace.CurrentCamera :: Camera
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart") :: BasePart
-- Variables
local enabled = false
local offsetY = 20
-- Click
clickDetector.MouseClick:Connect(function()
enabled = not enabled
end)
-- RunService
run.RenderStepped:Connect(function()
if enabled then
camera.CFrame = CFrame.new(rootPart.Position + rootPart.CFrame.UpVector*offsetY) * CFrame.Angles(math.rad(-90),0,0)
end
end)
-- Services
local run = game:GetService("RunService")
local players = game:GetService("Players")
-- Objects
local clickPart = workspace:WaitForChild("Part") :: BasePart
local clickDetector = clickPart:WaitForChild("ClickDetector") :: ClickDetector
-- Player & Charcater
local player = players.LocalPlayer
local camera = workspace.CurrentCamera :: Camera
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart") :: BasePart
-- Variables
local enabled = false
local offsetY = 20
-- Click
clickDetector.MouseClick:Connect(function()
enabled = not enabled
end)
-- RunService
run.RenderStepped:Connect(function()
if enabled then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(rootPart.Position + rootPart.CFrame.UpVector*offsetY) * CFrame.Angles(math.rad(-90),0,0)
end
end)
do you get any errors? i ran the code on my file and it worked.
afew things i would check for is:
1- make sure that the part with the click detector is the only part in workspace called “Part” or you can change the name.
2- errors.
how did your camera break, I looked at the latest code posted on this post and it seemed to work for me, and by that I mean when i click the part, the camera gives you a birds eye view. If you want to change it back, then you’ll need to add something to do that, but as far as making the camera look down at the player and staying in that angle it works