Why doesn't this camera script work when I use ClickDetector?

Basically, when you left click the ClickDetector on the part, it should change the part to the CFrame of the MenuCam, but it won’t work. I got the script from a GUI title screen thing I found, so I might believe that’s the reason, but other than that, I dunno.

Here’s the script:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	local plr = game.Players.LocalPlayer
	local char = plr.Character or plr.CharacterAdded:Wait()
	local camera = workspace.CurrentCamera

	repeat wait()
		camera.CameraType = Enum.CameraType.Scriptable
	until camera.CameraType == Enum.CameraType.Scriptable
	camera.CFrame = workspace.Menu.MenuCam.CFrame
	camera.FieldOfView = 120
	
	print("did it work?")
end)

I’ve been trying to do this for the past 20 minutes to no avail. I’ve searched other places on the DevForum and it didn’t help much.

1 Like
-- server script
local remote = game.ReplicatedStorage.RemoteEvent -- add a remote event

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    remote:FireClient(player)
end)

-- local script 
local remote = game.ReplicatedStorage.RemoteEvent

remote.OnClientEvent:Connect(function()
    local player = game.Players.LocalPlayer
    local char = plr.Character or plr.CharacterAdded:Wait()
	local camera = workspace.CurrentCamera

	repeat wait()
		camera.CameraType = Enum.CameraType.Scriptable
	until camera.CameraType == Enum.CameraType.Scriptable
	
	camera.CFrame = workspace.Menu.MenuCam.CFrame
	camera.FieldOfView = 120
	
	print("did it work?")
end)
1 Like

I put the script/local script/remove event into the right place but it still doesn’t work. It also won’t print the text/any errors, so I’m checking to see if anything before the print is broken.

menucamplace.rbxl (45.4 KB)

-- server script
local remote = game.ReplicatedStorage.NameOfYourRemoteEvent -- add a remote event

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    print("Player clicked.")
    remote:FireClient(player)
end)

-- local script 
local remote = game.ReplicatedStorage:WaitForChild("NameOfYourRemoteEvent")
local menuCam = workspace:WaitForChild("Menu").MenuCam

remote.OnClientEvent:Connect(function()
    local camera = workspace.CurrentCamera

	camera.CameraType = Enum.CameraType.Scriptable	
	camera.CFrame = menuCam.CFrame
	camera.FieldOfView = 120
	
	print("Set camera.")
end)

Try this.

It still only prints “Player clicked.” with no other errors. Does the RemoteEvent have to be a specific name?

You have to change the remoteevent’s name to whatever you like, then in the server and client, change “NameOfYourRemoteEvent” to, well, the name of the remote event.

I did that before and it didn’t work.

where are you putting the local script?

One issue that stands out is that you’re redefining the plr variable inside the function, which is unnecessary since you’re already passing it as a parameter to the function. And, the wait() function inside the repeat loop doesn’t have a specific purpose and can be removed.

Here’s a fixed version:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.Menu.MenuCam.CFrame
camera.FieldOfView = 120
print("did it work?")

end)

In the part of the ClickDetector. Is it supposed to be somewhere else?

Still didn’t work for some reason.

have you tried using the place I linked

For some reason (its probably my internet), it won’t download. Could you send an uncopylocked Roblox game?

What are you using? A LocalScript or a Script?

So, use it as a Script, in order to make it work.

You don’t need double “plr”, otherwise, the game is confused.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local camera = workspace.CurrentCamera
	local cameragoal1 = 120
	local cameragoal2 = 70

	repeat task.wait()
		camera.CameraType = Enum.CameraType.Scriptable
	until camera.CameraType == Enum.CameraType.Scriptable

	task.wait(0.07)

	if camera.CameraType == Enum.CameraType.Scriptable and camera.FieldOfView == cameragoal2 then
		camera.CFrame = workspace.Menu.MenuCam.CFrame
		camera.FieldOfView = cameragoal1
		print("Worked.")
		print("FOV: "..camera.FieldOfView)
	elseif camera.CameraType == not Enum.CameraType.Scriptable then
		print("Why is the Camera not Scriptable? Oh yeah, we didn't waited long enough, or the camera won't be scriptable.")
		--Do you want more if the camera's FOV is 120?
	elseif camera.FieldOfView == cameragoal1 then
		camera.FieldOfViev = cameragoal2
		print("FOV: "..camera.FieldOfView)
	end
end)

Oops, it was in a LocalScript. But, your script listed still doesnt work, with no errors : P

Note: This is a regular script not a localscript.
Click on the script and open the properties panel.
Change the RunContext to Client.
image

Thank you! This has worked! :slight_smile:

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