Camera CFrame isnt changing

Heyo! Trying to change the camera position through a remote event from a client script to a server script, but it isn’t working. I’ve done tests to confirm that the events are getting fired (prints), and they are indeed getting fired, but the camera type just isnt changing.

Both RemoteEvents are inside of ReplicatedStorage

Here’s the server code:

local camera = workspace.CurrentCamera

local camPart = workspace.MenuCamera

local CameraPosEvent = game.ReplicatedStorage.CameraPos
local CameraReset = game.ReplicatedStorage.CameraReset

CameraPosEvent.OnServerEvent:Connect(function()
	
	print("god this code is painful but works")
	camera.CameraType = Enum.CameraType.Scriptable

	camera.CFrame = camPart.CFrame
end)

CameraReset.OnServerEvent:Connect(function()
	print("NO")
	
	camera.CameraType = Enum.CameraType.Custom
end)

Below we have the client code:

-- Variables

local player = game.Players.LocalPlayer
local playerGUI = player.PlayerGui

local MainGUI = playerGUI.MenuScreen

local PlayModule = MainGUI.PlayModule

local TweenService = game:GetService("TweenService")

local TeleportationPad = workspace.TeleportationPad

local Event = game.ReplicatedStorage.CameraPos
local Event2 = game.ReplicatedStorage.CameraReset

-- PlayModule

PlayModule.Visible = true

PlayModule.MouseEnter:Connect(function()
	TweenService:Create(PlayModule.UIStroke, TweenInfo.new(0.3), {Thickness = 4}):Play()
end)

PlayModule.MouseLeave:Connect(function()
	TweenService:Create(PlayModule.UIStroke, TweenInfo.new(0.3), {Thickness = 1}):Play()
end)

PlayModule.PlayButton.MouseButton1Click:Connect(function()
	
	TweenService:Create(MainGUI.Transition, TweenInfo.new(0.5), {BackgroundTransparency = 0}):Play()
	wait(0.5)
	
	Event2:FireServer()
	
	player.Character:WaitForChild("HumanoidRootPart").CFrame= TeleportationPad.CFrame + Vector3.new(0, 3, 0)
	
	PlayModule.Visible = false
	wait(2)
	TweenService:Create(MainGUI.Transition, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
end)

-- Other

Event:FireServer()

You can’t change the camera of a player on the server. Do it on your LocalScript, I’m not sure why you tried it on the server first.

Code:

-- Variables

local player = game.Players.LocalPlayer
local playerGUI = player.PlayerGui

local MainGUI = playerGUI.MenuScreen

local PlayModule = MainGUI.PlayModule

local TweenService = game:GetService("TweenService")

local TeleportationPad = workspace.TeleportationPad
local Camera = workspace.CurrentCamera
local camPart = workspace:WaitForChild("MenuCamera")

-- PlayModule

PlayModule.Visible = true

PlayModule.MouseEnter:Connect(function()
	TweenService:Create(PlayModule.UIStroke, TweenInfo.new(0.3), {Thickness = 4}):Play()
end)

PlayModule.MouseLeave:Connect(function()
	TweenService:Create(PlayModule.UIStroke, TweenInfo.new(0.3), {Thickness = 1}):Play()
end)

PlayModule.PlayButton.MouseButton1Click:Connect(function()

	TweenService:Create(MainGUI.Transition, TweenInfo.new(0.5), {BackgroundTransparency = 0}):Play()
	task.wait(0.5)
	
	Camera.CameraType = Enum.CameraType.Custom

	player.Character:WaitForChild("HumanoidRootPart").CFrame= TeleportationPad.CFrame + Vector3.new(0, 3, 0)

	PlayModule.Visible = false
	task.wait(2)
	TweenService:Create(MainGUI.Transition, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
end)

-- Other
task.wait(0.1)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = camPart.CFrame

I tried it on the client first, then it wasn’t working, so I assumed it was on the server.

1 Like

What “didn’t work” on the client?

My persisting issue, the camera not changing. But let me try and change it back first,

You most likely need to add a wait before modifying the camera. Try my edited code.

Thank you. Camera’s definitely aren’t my strong point in programming.

1 Like

Don’t worry, at least you tried some solutions before going to the devforum. If I was in your perspective I wouldn’t have known you have to add a wait either, I only know because I’ve experienced the same problem as you before.

Anyways, Merry Christmas!

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