Resetting camera not working?

I looked at other solutions but I am still kind of puzzled. So I’m making a 2d platformer and the platformer was working fine until I add a if value == true statement. Then it broke… I want the value to become true and then the camera will reset but the camera resets even if the value is false. Local script inside of starter gui.

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local rc = game.ReplicatedStorage:WaitForChild("Mutators"):WaitForChild("Reset Camera")

rc.Changed:Connect(function(val)
if val == false then
	repeat
		wait()
	until Player.Character

	local Player = Player.Character
	local HumanoidRootPart = Player.HumanoidRootPart


	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = Player.HumanoidRootPart

	game:GetService("RunService").RenderStepped:connect(function()
		Camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X, HumanoidRootPart.CFrame.Y, HumanoidRootPart.CFrame.Z + 30)
		Camera.FieldOfView = 50
	end)
else
	print("hi") -- dont mind this I was just trying to print something
			Camera.FieldOfView = 70
			Camera.CameraType = Enum.CameraType.Custom
			Camera.CameraSubject = Player:WaitForChild("Humanoid")
	end
end)

val is going to be the name of the property that changed, not the value itself. Instead of “if val == false”, do this:

if rc.Value == false then

I also tried that and same result. It didn’t work

Any errors in the output??____

Nope, no errors in the output, though it prints “hi”, the test print

And you change the value from true to false, and it still prints “hi”?

yeah, it prints hi when i change the value

Why is the variable for player and character same.

because you don’t need to use local player for camera manipulation

Have you tried this
Local Character = Player.Character or Player.CharaterAdded:Wait()

Instead of this
Local Player = Player.Character

but wouldn’t the character be already loaded in by the time the value changes?

Sometimes it takes longer for character to load.

No, it didn’t work… I tested it out

Oh, well did you change
local HumanoidRootPart = Player.HumanoidRootPart

Camera.CameraSubject = Player.HumanoidRootPart

To
local HumanoidRootPart = Character:WaitForChild(‘HumanoidRootPart’)

Camera.CameraSubject = Humanoid

And why there’s a end) between if statement and else statement.

Because of the renderstepped function and I will try that

No, I don’t think that worked…

1 Like

Do you know what I should change?

I think something is wrong with the if statement, the else statement seems to be working bcuz you said the output prints hi.

Btw have you checked the camera’s cameraType when the value is true ?

I figured out that the value was changed in a server script not a local script so the value didn’t change but there is another issue, when I die the camera stays in one spot not following the player.