Never use while wait() do
; it’s poor practice, especially in this case because it doesn’t loop nearly fast enough to make the camera smooth. Instead, use RunService as explained in this DevHub article.
To put it simply, this error means that you haven’t actually found the player’s character. This may be either because your script runs on the server or because the player’s character hasn’t loaded yet when you were initialising the character
variable. If this is a local script, you could simply use this:
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
That line is explained in the first post that I linked.