To get the script attached to a node simply use get_script() on that nodes instance
Before i go any further know that collider to which you obtain a reference must be a CollisionObject or Inherited form of.
So if a script is not attached to it then you'll want to use that instance to get the node that does have the script attached
"To get the script attached to a node simply use get_script() on that nodes instance"
That returns the script as if loaded from a NodePath but having that information is probably not what you want as you cant access a members variables using that.
The collider you get from the rayCast using for example
$RayCast.get_collider() is the actual instance you want and to access its variables just use
$RayCast.get_collider().variable assuming you have a valid collision of course
var speed = 1
var enemies = Array()
In the image above My Agent node has Agent.gd script attached, notice that all variables defined in Agent.gd become members of the Agent node instance
Mesh node child of
Target also has the same script attached so if i did a rayCast i'd get the
Target node since it is the CollisionObject, so to get the members
var node = $RayCast.get_collider()
if node: node.get_child("Mesh").speed = 4