I am making a lobby system that allows players to create a lobby or join lobbies others have created. I already have a working creation system and listing system. Now I am just trying to make a script that allows players to click a join button to join a listed server.
My problem is that when I invoke this remote function, I am trying to send the name of the server that they are trying to join with it. However, when I do this, I get this error: “Unable to cast value to Object”.
This script is a local script that is parented to the join button of a listed server.
local JoinServer = workspace.Events.JoinServer
local JoinButton = script.Parent.JoinButton
JoinButton.MouseButton1Click:Connect(function(plr)
local ServerName = JoinButton.Parent.Name
for i, Server in pairs(ServerFolder:GetChildren()) do
if Server.Name == ServerName then
local ServerOwnerName = Server.ServerOwner.Value
local ServerOwnerUserId = PlayerService:GetUserIdFromNameAsync(ServerOwnerName)
print(ServerOwnerUserId, "UserID")
local Success = JoinServer:InvokeServer(ServerName)
if Success == true then
The line that causes the error is local Success = JoinServer:InvokeServer(ServerName)
This is not the entire script, but I feel this is what is necessary to share.
When I send a string it works just fine. If I send a variable containing the string though it comes out with an error again. I’m not entirely sure what a stack trace is but I think you are asking for this:
This error happens on the Client. The Client is supposed to send the server the name of the lobby the player is attempting to join. Here is the server side of the function. Please keep in mind that I am not yet done with this part as I am trying to resolve the current issue.
JoinServer.OnServerInvoke = function(plr, ServerName)
print(ServerName)
local AmountOfPlayers = 0
local Success = false
for i, Server in pairs(ServerFolder:GetChildren()) do
print(ServerName, Server.Name)
if ServerName == Server.Name then
for i, PlayerAmount in pairs(Server.Players:GetChildren()) do
AmountOfPlayers += 1
end
print("True 2")
if AmountOfPlayers < 2 then
local AddPlayer = Instance.new("StringValue")
AddPlayer.Parent = Server.Players
AddPlayer.Name = "Player2"
AddPlayer.Value = plr.Name
local AddedPlayer = plr
PlayerAdded:FireClient(ServerName, AddedPlayer)
Success = true
else
Success = false
end
end
end
return Success
end