Why does my IF statement not work?


script.Parent.Parent.PlayerGui:WaitForChild("ScreenGui").Frame.TextButton.MouseButton1Click:Connect(function()
print(1)
if not workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable then
print(2)	
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = workspace.CameraParts.Cameracframe.CFrame
workspace.CurrentCamera.Focus = game.Workspace.CameraParts.Camerafocus.CFrame

else
print(3)	
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	end
	print(4)
end)

When I run the script and press the button, it does not work, it only ever prints out 1,3 and 4 even if my cameratype is not scriptable

Replace it with:

if not (workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable) then

Or more simply:

if workspace.CurrentCamera.CameraType ~= Enum.CameraType.Scriptable then

This is because the unary not operator has precedence over the equals == operator.
https://www.lua.org/pil/3.5.html

4 Likes

Yay thank you! Now the camera does change, how did i not think of that?