Camera won't go to part

I want it so that the players camera (local player) goes to a specific part location (CFrame)

The issue is that nothing happens. I even added a “print” to see and I have nothing in my output. It is a ProximityPrompt that runs on a function (triggered)

Code

local UserInputService = game:GetService("UserInputService")

script.Parent.Triggered:Connect(function(Player)
	local camera = game.Workspace.Camera
	local part = game.Workspace.Camera1

	if (workspace.CurrentCamera.CameraType == Enum.CameraType.Custom) then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = part.CFrame
		print(Player.DisplayName.." has changed their camera to the street camera!")
	end

	local function Input(input, gameProcessed)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Space then
				camera.CameraType = Enum.CameraType.Custom
			end
		end
	end
end)

Does anybody know? The proximity prompt is located inside the part and the script is inside the proximity prompt.

1 Like

It’s likely that the if statement itself is preventing both the print statement and camera change code from happening. Is it there to verify the player’s CameraType?

I’m learning a bit about the player camera. I have no idea if this script only changes the local player camera or everyones camera. (I only want the local player camera to change)

For now, I suggest testing the code first without the said if statement since the player’s CameraType is normally on Custom (not discouraging you to use it or anything).

Alongside this, is this script a localscript? If so, where is it stored?

The script is located inside a “ProximityPrompt” which is inside a part.

The script is a server script.

So I tried that and it prints that my camera changed but my camera hasn’t changed. It printed but my camera stayed the same…

I don’t think server scripts are able to modify the player’s camera, but I could be wrong.

I suggest making it fire a remote to the client, and then have a localscript handle the camera changing.

Should the local script be inside StarterGui?

StarterGui would definitely be a place you can put it in.

ProximityPrompt script inside the said part:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("Remote")
local ProximityPrompt = -- proximity prompt itself

ProximityPrompt.Triggered:Connect(function(player)
    Remote:FireClient(player)
end) 

Client code/localscript inside StarterGUI:

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteName")

Remote.OnclientEvent:Connect(function()
       --camera changing code here
end)

You can also use UserInputService/ContextActionService within localscripts here too, so your extra code that cancels out the player from the camera should work fine here.

1 Like

It works! Omg thanks a lot! I thought about remote events for a second and they do work!

1 Like

Remotes are always a nice and useful thing to have in problems like these. Glad you got the outcome!

1 Like