How can I run a script with sudo? I get ".: command not found"

You need to run

sudo ./scriptfile

You tried

sudo . /scriptfile

which is different due to the space after the dot. . or it's equivalent source is a shell builtin, not a command. That's why the command you tried produces the error sudo: .: command not found.

Note:

./scriptfile

will execute the file with the name scriptfile in the current directory. The file needs to be executable.

. /scriptfile

will source the file /scriptfile (remind that this is an absolute path here). The file doesn't need to be executable to do this, it only needs to be readable.