Hello!!
In my script it detects if the player presses the enter key and if they typed in the right serverID (a 5 number randomized code given to serverCreators who can invite people to their server.)
When the player enters the right serverID, the player is unable to join the server and the output says some warning. (Red lines are not relevant to the issue.)
Any solutions?
Local script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JoinBTN = script.Parent.ServerSelect.JoinServerBTN
local JoinTextBox = script.Parent.ServerID.TextBox
local ScreenGUI = script.Parent
local Players = game:GetService("Players")
local ServerIDImage = ScreenGUI.ServerID
local Server = ScreenGUI.Server
local CreatorPanel = ScreenGUI.Server.CreaterPanel
local ServerIDNum = ScreenGUI.Server.CreaterPanel["Server ID"].SERVERIDNumber
local ServerName = ScreenGUI.Server.ServerName
local function onEnterPressed()
local ServerID = JoinTextBox.Text
if ServerID and ServerID ~= "" then
print("Attempting to join server with ID:", ServerID)
local success = ReplicatedStorage.JoinServer:InvokeServer(ServerID)
print("JoinServer")
if success then
print("Successfully joined the server.")
ServerIDImage.Visible = false
Server.Visible = true
CreatorPanel.Visible = false
Server.Position = UDim2.new(0.5,0,0.5,0)
ReplicatedStorage.JoinServerServer:FireServer()
else
warn("Failed to join the server.")
end
else
warn("ServerID is nil or empty")
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Return then
onEnterPressed()
end
end)
JoinBTN.MouseButton1Click:Connect(function()
onEnterPressed()
end)
ServerScript:
ReplicatedStorage.JoinServer.OnServerInvoke = function(player, ServerID)
for _, server in ipairs(ListofIds:GetChildren()) do
if server.Value == ServerID then
print(player.Name .. " successfully joined server with ID:", ServerID)
return true
end
end
warn(player.Name .. " failed to join server with ID:", ServerID)
return false
end
ReplicatedStorage.CreateServerServer.OnServerEvent:Connect(function(player)
ReplicatedStorage.CreateServerPlayer:FireAllClients(player)
end)
ReplicatedStorage.JoinServer.OnServerInvoke = function(player)
ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end
There are more to the ServerScript but I don’t think it is relevant, if you want the full script ask me!