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

I have problems with my 2d camera script?

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")
workspace.clickpart.ClickDetector.MouseClick:Connect(function()
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Follow
camera.FieldOfView = 40
end)
game:GetService('RunService').Stepped:Connect(function()
 camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)
end)

I want to make it so that when the player clicks the click detector, his camera will change to this 2d one. There's nothing in the output, but it doesn't work. Can someone figure it out?

2 answers

Not sure if the camera angle is right, but you can change that. Here's the code:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local Character = player.Character or player.CharacterAdded:Wait()
local RootP = Character:WaitForChild("HumanoidRootPart")
local Clicked = false
game.Workspace.clickpart.ClickDetector.MouseClick:Connect(function()
camera.CameraSubject = Character
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 40
Clicked = true
end)
game:GetService('RunService').Stepped:Connect(function()
	if Clicked then
		game:GetService("TweenService"):Create(camera,TweenInfo.new(0.3,Enum.EasingStyle.Linear),{CFrame = CFrame.new(RootP.Position) * CFrame.fromEulerAnglesXYZ(0,0,0)+ Vector3.new(0,5,50)}):Play()
		else
	end
end)

Hope this helps! :)

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