I currently purchased a new server box under a new IP and I was wondering if it was possible to make a script to put in my old server so that when ever someone joins my old server they will automatically connect to my new one.
PlayerInitialSpawn and pl:ConCommand(“connect newip”)
or you can just lock the server and change the hostname to “!!!NEW IP: whatever!!!”
PlayerInitialSpawn and pl:ConCommand(“connect newip”) Ended up not working. I placed that in file in lua/autorun
hook.Add("PlayerInitialSpawn", "8==D", function(ply) ply:ConCommand("connect 127.0.0.1") end)
I ended up getting this “FCVAR_SERVER_CAN_EXECUTE prevented server running command: connect”
This should work:
function Redirect(ply) ply:SendLua([[RunConsoleCommand("connect", "<INSERT IP HERE>")]]) end hook.Add("PlayerInitialSpawn", "RedirectClient", Redirect)
My game ends up crashing after sending client info. I had multiple people try and connect and it crashes there game to.
Learn how to use the net library
util.AddNetworkString "LeaveThisServerAtOnce" hook.Add("PlayerInitialSpawn", "Redirect", function(ply) net.Start "LeaveThisServerAtOnce" net.Send(ply) end)
net.Recieve("LeaveThisServerAtOnce", function() RunConsoleCommand("connect", "ip") end)
This is purely clientside. No networking or server involvement. However, it will be called a little while after PlayerInitialSpawn is called serverside. Pretty much the moment they have control over their character.
hook.Add( "InitPostEntity", "Redirect", function() LocalPlayer():ConCommand( "connect <Your IP Here>" ) end )
Thank you very much. That ended up working.