I am trying to make a script where clicking on a part (which is the keyhole) to view inside the door. I don’t get any errors when running but it also isn’t working, I am not sure if I typed it correctly, but It’d be great to get some help.
Server script:
local Highlight = script.Parent.Highlight
local TouchBox = script.Parent.TouchBox
local Click = script.Parent.TouchBox.ClickDetector
local Camera = script.Parent.Parent.Parent.Camera
local KeyCamPart = script.Parent.KeyCamPart
TouchBox.ClickDetector.MouseHoverEnter:connect(function()
Highlight.Enabled = false
end)
TouchBox.ClickDetector.MouseHoverLeave:connect(function()
Highlight.Enabled = false
end)
TouchBox.ClickDetector.MouseClick:Connect(function()
repeat
Camera.CameraType = Enum.CameraType.Scriptable
wait(.1)
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = KeyCamPart.CFrame
end)
You are trying to get the camera from script.Parent.Parent.Parent.Camera. If you want to get the local player’s camera, use workspace.CurrentCamera instead. Also, make sure that your script is under StarterPlayerScripts, and not ServerScriptService.
If it’s not under StarterPlayerScripts, it will just be a localscript on the server, instead of the client.
I wrote a script that does what you want to do, just with a little less details
local camera = workspace.CurrentCamera
local keyhole = game.Workspace.keyhole.ClickDetector
local campart = game.Workspace.camera
keyhole.MouseClick:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = campart.CFrame
end)