The url that your function returns should work fine. But, for the purpose that you are looking for, this is what I recommend.
You need to first get the ID from the url. To do this, use string.find to find the position of the equal sign, then string.sub to remove everything but the ID.
local url = "http://www.roblox.com/asset/?id=6160938171"
local ID = string.sub(url, string.find(url,"=")+1, string.len(url))