Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing Camera Position/CFrame not working?

Hi! I'm making a camera script so I can learn how to use it but I have ended with a problem that the camera isn't changing its position. Please help!

Script in ServerScriptService:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("ChangeCamera")
	

local function onCharacterAdded(Player,Char)
	remoteEvent:FireClient(Player,Char)
end

local function onPlayerAdded(Player)
	Player.CharacterAdded:Connect(function(Char)
		onCharacterAdded(Player, Char)
	end)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

Script in LocalScript:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("ChangeCamera")

local function cameraChange(Player, Char)
	local cam = workspace.CurrentCamera
	cam.CameraType = Enum.CameraType.Scriptable
	local campos = game.Workspace.CameraPart.Position
	local focuspartpos = game.Workspace.FocusPart.Position
	print(campos)
	print(focuspartpos)
	local camCFrame = CFrame.new(campos, focuspartpos)
	cam.CFrame = camCFrame
end

remoteEvent.OnClientEvent:Connect(cameraChange)

4 comments

0

I meant LocalScript in StarterPlayerScripts btw sorry

0

You don't need remote events to modify the camera, the players client has access to it. But other than that the code looks fine, are your prints firing and it just not moving, or does that whole code not fire?

0

the prints are firing but the camera did noot change cframe

0

Im looking into it right now. I tested your code and got an error I've never seen before, so I googled it. Roblox introduced a new car camera system a few weeks ago, and since then this error message has been spamming peoples games since, and Roblox said they won't look into it until after the holidays. If I can find something out, or fix your code, i'll post back.

1 answer

✓ Accepted answer

Alright so I found a temporarily solution. I really think your code was breaking because of the car update system, but digging around somebody found a fix for it. Once Roblox fix's the bug, you shouldn't have to setup cameras like this, but until then.

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	workspace.Camera.CameraType = Enum.CameraType.Custom
	wait()
	workspace.Camera.CameraType = Enum.CameraType.Scriptable
	local cam = workspace.CurrentCamera
	local campos = game.Workspace.CameraPart.Position
	local focuspartpos = game.Workspace.FocusPart.Position
	print(campos)
	print(focuspartpos)
	local camCFrame = CFrame.new(campos, focuspartpos)
	cam.CFrame = camCFrame

3 comments

0

You must always reference CurrentCamera.

0

Thank you so much it worked and I have accepted your answer

0

Obviously ziffixture, however the camera scripts are bugged and this is currently one of the ways to fix it. This is a hacky code to temporarily get around the bug that was introduced with the car camera update

This discussion is preserved as it was. New answers, comments, and votes are closed.