How to make the camera view go to a part upon clicking a click detector button in workspace

local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(presser)
	if db == false then
              db = true
	end
	
end)

this is what i have so far, i made a camera part in workspace and the title is self explanatory

I’m assuming you want the player to be able to move the Camera around while being focused on the part, if you want a CFrame based Camera system you would use the Scriptable CameraType and set the Camera’s CFrame.

However, to make it so the player can look around whilst focusing on the part, it’s very simple:

workspace.CurrentCamera.CameraSubject = *your part*

So, integrating that into your script would be something like:

local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(presser)
	if db == false then
              db = true
              workspace.CurrentCamera.CameraSubject = *your part*
	end
end)

However, if you want to go the CFrame route, it’d be something like this:

local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(presser)
	if db == false then
              db = true
              workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
              workspace.CurrentCamera.CFrame = *yourpart*.CFrame
	end
end)
3 Likes

but it will only be for the player who clicked right?.

1 Like

To add that, just do:

local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(presser)
    if presser ~= game.Players.LocalPlayer then return end
	if db == false then
              db = true
              workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
              workspace.CurrentCamera.CFrame = *yourpart*.CFrame
	end
end)

this is a script in a part in workspace, game.Players.LocalPlayer still works?

By the way it is not working. Sorry

No. In order for the Camera manipulation and LocalPlayer to work, it has to be on a LocalScript. If needed, you could set your script’s RunContext to Client and it should work. (This allows you to keep it in workspace, as LocalScripts do not run in workspace.)

1 Like

Woah you just teached me something new, im gonna try that out

Thanks it works! and how do i get out of it?

Just run:

workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

And it will go back to the default camera type.

thanks you very much for the help. Have a nice day

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.