You are running with an async problem.
When your function return the value (the line return ip[0]) the connection.query() hasn't been returned, because is an async function. So you are returning the value ip[0] without actually running the MySQL query, so the ip value stills equal to [] (the same when defined), so ip[0] is undefined.
For example, the same happend in here:
function getAddress(banned) {
let ip = [];
setTimeout(function() {
ip = ["hi", "world"];
console.log("IP value is now:" + ip[0])
}, 2000);
console.log("I am returning the IP value: " + ip[0])
return ip[0];
}
getAddress()
With the following output:
I am returning the IP value: undefined
IP value is now: hi
As you can see, the return statment happens before the callback of the setTimeout which modified the ip variable, the same with your connection query function.
What you could do is to make your function async, and await for the results to complete on a synchronous way.
I haven't tried this one in particular, but something like this should work:
async function getAddress( banned ){
const rows= await connection.query(`SELECT Ips FROM sc_alts WHERE Name LIKE '${banned}'`)
return rows[0].Ips;
}
See Node.js Using async/await with mysql for some reference