Lock cursor help

I have tried to make a script that locks the cursor in the center of the screen but it doesn’t work. Here’s my code:

function Start () {
	
	Screen.lockCursor = true;
	
}

All help would be appreciated, thanks!
By the way my preffered language is javascript.

Vector3 mousePos = Input.mousePosition;
mousePos.x = Screen.width / 2;
mousePos.y = Screen.height / 2;
Input.mousePosition = mousePos;

puts it in the center.

jimmy_games5634 , Your script is ok ,it does what it should ,you can test in the build version ,however in Unity editor it wont work ,it will just hide the mouse but it will not center it in the middle of the screen.