How would I make a camera change from 3d to 2d?

I’m new to Roblox development so sorry if this is really obvious.

I’m trying to make it so when the player touches a part it would change the camera from 3d to 2d and back, similar to the system Super Mario Odyssey has.

So far I’ve just tried making a touch function and putting a 2d camera script into it, but that hasn’t worked. I also haven’t seen anything related to this on the DevForum.

Any help is appreciated!

1 Like

Can you show your current script?

1 Like
local CameraChanger = script.Parent
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local function PlayerTouched(Part)

	player.CharacterAdded:Wait()
	player.Character:WaitForChild("HumanoidRootPart")

	camera.CameraSubject = player.Character.HumanoidRootPart
	camera.CameraType = Enum.CameraType.Attach
	camera.FieldOfView = 40

	game:GetService('RunService').Stepped:Connect(function()
		camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)
	end)
end

CameraChanger.Touched:connect(PlayerTouched)

This probably doesn’t work at all.

1 Like

Set the camera to only face one direction so the player can’t turn the screen when they are 2d.

1 Like

Probably? Did you test it? Did it error, or was it something else?

1 Like

Yeah I tested it and by probably I mean even with readjustments it wouldn’t work.

1 Like

I think the problem is that Local Scripts don’t run under the workspace (with the exception of characters and tools in the player’s backpack).

1 Like

So how would I put a local script in a part that’s in workspace?

1 Like

You don’t. You put the local script in StarterPlayerScripts, and modify the script accordingly. If you want multiple camera changing parts, use CollectionService.

1 Like

Okay I’ll try making that work. Thank you!

1 Like