Issue with setting players camera

im making a system where when you run a command like !camera1 or !camera2 it’ll set the currentcamera to that camera, the issue is that it isn’t changing the camera and im not sure why.

Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local cameraNames = {“!camera1”, “!camera2”, “!camera3”, “!camera4”, “!camera5”}
local cameraObjects = {Workspace.Cameras.Camera1, Workspace.Cameras.Camera2, Workspace.Cameras.Camera3, Workspace.Cameras.Camera4, Workspace.Cameras.Camera5}

  for i, cameraName in ipairs(cameraNames) do
  	if string.find(message, cameraName) then
  		print("Player has ran a camera command")
  		local camera = player.CameraMode == Enum.CameraMode.LockFirstPerson and player.Character.Humanoid.Viewpoint or workspace.CurrentCamera

  		camera.CameraType = Enum.CameraType.Scriptable
  		camera.CFrame = cameraObjects[i].CFrame
  	end
  end

end)
end)

" Camera objects exist only upon the viewer’s client, residing in that user’s local Workspace, and therefore cannot be edited directly from the server. Each client’s particular Camera object can be accessed through the Workspace "

You would need to use a local script to acces the currentCamera

Here is an Example:
Serverscript:

local Players 			= game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camObjects		= {workspace.camera1,workspace.camera2}
local camCommands		= {"!camera1","!camera2"}
local camHandlerEvent	= ReplicatedStorage:WaitForChild("changeCamEvent") 

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		for index, camCommand in pairs(camCommands) do
			if camCommand == message then
				local camObject = camObjects[index]
				
				camHandlerEvent:FireClient(player,camObject)
			end
		end
	end)
end)

Localscript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camHandlerEvent	= ReplicatedStorage:WaitForChild("changeCamEvent") 

camHandlerEvent.OnClientEvent:Connect(function(object)
    if not object then
        camera.CameraType = Enum.CameraType.Custom
    end

	local cFrame = object.CFrame
	local camera = workspace.CurrentCamera
	
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = cFrame
end)

Hope this helped!

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