Set object position to:
clamp( Self.X, ViewportLeft( Self.LayerName ), ViewportRight( Self.LayerName ) )
clamp( Self.Y, ViewportTop( Self.LayerName ), ViewportBottom( Self.LayerName ) )
Sorry, it doesn't work. All it does is makes the object move when it's off the screen. Thanks for your help, though!