Camera 2D Error

hello developers, I have a problem with a localscript, I’m looking for a solution, I explain when I touch a part my camera switches to 2D camera for example it’s in first person and touching a part puts it in 2d camera

the problem is that when the player dies having the 2d camera activated, that is, I activate it from another localscript, it bugs because the script is restarted and disabled, how can I make the script remain enabled at the time of death, also being in 2d

I pass images to explain myself…
image



the code is just a touched part with a localscript.enabled = true end

any solution is appreciated, thanks

1 Like

The scripts would have to not be in the character or you would have to make it re-initialize upon spawn. Also, are your circles and arrows ok?? do they need to see a doctor?

1 Like

You should move the script into StarterPlayer.StarterPlayerScripts, not StarterPlayer.StarterCharacterScripts.

1 Like

I did it but it bugs the same :frowning:

1 Like

Sorry for the late response, but can you please show me the code you use for the camera?

I’ll pass you the site, Sorry if I’m taking up your time, I’m still a novice programmer.
2DCamera.rbxl (40,6 KB)

Ok, I finished rewriting your script, here it is.

local RunService = game:GetService('RunService')

local Plr = game:GetService('Players').LocalPlayer

local Camera = workspace.CurrentCamera
local is2D = false

Plr.CharacterAdded:Connect(function(Char)
	RunService:UnbindFromRenderStep(Plr.UserId)
	
	local rootPart:BasePart = Char:WaitForChild('HumanoidRootPart')
	
	local function UpdateCamera()
		if is2D then
			local Goal = CFrame.lookAt(
				rootPart.Position + Vector3.new(0, 15, 50),rootPart.Position -- Look from the rootPart position plus (0,15,0) towards the rootPart position
			)
			
			Camera.CFrame = Camera.CFrame:Lerp(Goal,.3) -- Lerp the camera CFrame
			Camera.CameraType = Enum.CameraType.Scriptable
		else
			Camera.CameraType = Enum.CameraType.Custom
		end
	end
	
	RunService:BindToRenderStep(Plr.UserId,1,UpdateCamera)
end)

workspace.Part.ProximityPrompt.Triggered:Connect(function(p)
	if p == Plr then is2D = not is2D end -- Toggle 2D variable
end)

Place this in a LocalScript inside StarterPlayerScripts.

WORKS PERFECTLY :ok_hand:
thanks for your help

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