Player is unable to join a server

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.)
image_2024-12-31_161040048

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!

1 Like

Don’t know if this intentional but you have your event as JoinServerServer if not to be JoinServer

1 Like

It is supposed to do that. I know it looks wierd.

Ok gotcha, also could i see the part the sends the player to the server
ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
I might be able to help (:man_shrugging:…)

1 Like

I’m not entirely sure what you mean. But here is the part

ReplicatedStorage.CreateServerServer.OnServerEvent:Connect(function(player)
	ReplicatedStorage.CreateServerPlayer:FireAllClients(player)
end)

ReplicatedStorage.JoinServer.OnServerInvoke = function(player)
	ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end

i meant the portion of the code where the player is actually sent to the server from this line ReplicatedStorage.JoinServerPlayer:FireAllClients(player)

1 Like

Silly me

game.ReplicatedStorage.JoinServerPlayer.OnClientEvent:Connect(function(player)
	print(player)
	local playerTextClone = PlayerNameText:Clone()
	playerTextClone.Text = Players.LocalPlayer.Name
	playerTextClone.Parent = script.Parent
end)

Also I changed this code from JoinServerServer to JoinServerPlayer

ReplicatedStorage.JoinServer.OnServerInvoke = function(player)
	ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end

And it printed out the print statement but still said failed to join server.
image_2024-12-31_173020825

Where it says “planeboy2021” is my print statement from the reply above.

I found the Solution!

This bit was JoinServer instead of JoinServerServer, and when I changed it it worked!

It was for this at the bottom of the server script

ReplicatedStorage.JoinServerServer.OnServerEvent:Connect(function(player)
	ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end)
1 Like

aw nice, i was trying to redo what you did so i could find a solution and acc got somewhere but glad you found it :sob:
image
i just changed the remote function to a remote event it was giving better results lol

1 Like

Thank you for helping me though!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.