Hello!
A player can create a server/lobby with a unique code called ServerID. Players can enter that code to join the server/lobby. When the right code has been typed it says these two warnings:
Failed to join server with ID: planeboy2021
Failed to join the server
Another issue is that in the JoinServerHandler, at the bottom of the script, it should print “recieved” but it doesn’t
I have made three scripts, a local and server script.
The two local scripts are in charge of the ui and when the player clicks on a button. Two two scripts are called. JoinServerHandler and ServerJoinCreateScript
JoinServerHandler = detects if player has pressed the JoinServerBTN (this pops up a ui for the player to type in the ServerID) Then once the player has typed the ServerID and presses the enter key which fires a remote function. Here is where the Failed to join the server warning is located.
ServerJoinCreate Script = detects when the player has clicked the CreateServerBTN, then fires a remote function to the server. It also adds some ui changes.
ServerScript = In charge to make the ServerID when the player makes a new server, and to delete the ServerID when the player leaves the game. Here is where the Failed to join server with ID: planeboy2021 warning is located.
I have added a print statment which prints “received” The recieved never gets printed, and it is supposed to get printed.
If you have any questions ask me!!
full scripts:
local: JoinServerHandler
local UserInputService = game:GetService("UserInputService")
local JoinBTN = script.Parent.ServerSelect.JoinServer
local JoinTextBox = script.Parent.ServerID.TextBox
local players = game:GetService("Players").LocalPlayer
JoinBTN.MouseButton1Click:Connect(function()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Return then
print("keycode")
local ServerID = JoinTextBox.Text
if ServerID and ServerID ~= "" then
local success = game.ReplicatedStorage.JoinServer:InvokeServer(players, ServerID)
if success then
print("Successfully joined the server.")
else
warn("Failed to join the server.")
end
else
warn("ServerID is nil or empty")
end
end
end)
end)
game.ReplicatedStorage.JoinServer.OnClientInvoke = function()
print("recived")
end
local: ServerJoinCreateScript
local ScreenGUI = script.Parent
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CreateBTN = ScreenGUI.ServerSelect.CreateServer
local JoinBTN = ScreenGUI.ServerSelect.JoinServer
local JoinTextBox = ScreenGUI.ServerID.TextBox
local CreaterPanel = ScreenGUI.Server.CreaterPanel
local ServerName = ScreenGUI.Server.ServerName
local ServerIDNum = ScreenGUI.Server.CreaterPanel["Server ID"].SERVERIDNumber
ScreenGUI.Server.CreaterPanel.Visible = false
CreateBTN.MouseButton1Click:Connect(function()
local ServerID, isPrivate = game.ReplicatedStorage.CreateServer:InvokeServer()
if ServerID then
print(ServerID)
ScreenGUI.ServerSelect.Visible = false
ScreenGUI.Server.CreaterPanel.Visible = true
ScreenGUI.Server.Visible = true
ServerIDNum.Text = tostring(ServerID)
ServerName.Text = Players.LocalPlayer.Name.. " 's SERVER"
else
warn("ServerID is nil")
end
end)
Server Script:
local players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
game.ReplicatedStorage.CreateServer.OnServerInvoke = function(player, code)
local ServerID = Instance.new("IntValue")
ServerID.Value = math.random(10000, 99999)
ServerID.Parent = ServerScriptService.ServerIDHandler.ListofIds
ServerID.Name = player.Name.. " 's Server"
players.PlayerRemoving:Connect(function(plr)
if plr == player then
local playerServerID = ServerScriptService.ServerIDHandler.ListofIds:FindFirstChild(plr.Name.. " 's Server")
if playerServerID then
playerServerID:Destroy()
end
end
end)
return ServerID.Value
end
game.ReplicatedStorage.JoinServer.OnServerInvoke = function(player, ServerID)
local playerServerID = ServerScriptService.ServerIDHandler.ListofIds:FindFirstChild(player.Name.. " 's Server")
if playerServerID and playerServerID.Value == tonumber(ServerID) then
print("Successfully joined server with ID:", ServerID)
return true
else
warn("Failed to join server with ID:", ServerID)
return false
end
end