There is more wrong than right in your piece of work 
As it is now you script attaches a slider to a single layer (mySolid, the one you add at the beginning).
That's not very useful, you can't use that slider for other layers.
You should also keep in mind that that solid can be deleted, hence the mySolid object can become invalid (refering to an solid that doesnt exist anymore).
I don't know what exactly is your plan, but usually a script does not define any AE-related object in its many body (upon launching).
Only when the user clicks/changes a widget the script tries to retrieve a comp, layer, property or whatever that the user has specified through "some kind of secret code" (most of the time: the comp, layer, property, etc, is selected).
If you wanted the slider to control the opacity value of all selected layers in the active comp, it would be something like this:
var myWin = new Window("palette", "Transform", undefined); //create pallete
myWin.orientation = "row";
var myOpacity = myWin.add("panel", undefined, "Solid Opacity");
myOpacity.orientation = "column";
myOpacity.add("statictext", undefined, "Kontrol Opacity");
var opacitysliderCtrl = myOpacity.add("slider", undefined, 50, 0, 100);//make slider
opacitysliderCtrl.onChanging = function onOpacitySliderChanging(){
// retrieve the AE things that have to be handled: in this case, all selected layers in the active comp
var myComp, myLayer, n;
var layerOpacity, val;
myComp = app.project.activeItem;
if (myComp.numLayers>0){
for (n=0; n<myComp.selectedLayers.length; n++){
myLayer = myComp.selectedLayers[0];
if (myLayer.hasVideo){
// you forgot the .transform there:
var layerOpacity = myLayer.transform.opacity;
// var val = Math.round(opacitysliderCtrl.value) can work but the following is better
var val = Math.round(this.value);
// you can't set a property's value by just writing property.value=val
// you must use setValue:
// layerOpacity.value = val;
layerOpacity.numKeys ? layerOpacity.setValueAtTime(myComp.time, val): layerOpacity.setValue(val);
};
};
};
return;
};
myWin.center();
myWin.show();
Xavier