You can't sort on a script field, because script fields are only calculated for the hits that are being returned. In other words, your hits have already been sorted before the script fields are calculated.
What you may want to look at instead is script based sorting. The docs have an example of that. What's nice about script based sorting is that the scripted values that are used for sorting will be returned with the hits. So you may not need the script fields if you use script based sorting