I am actually working on a game with a similar “code” mechanic, and what I did is, I made so when a player creates a lobby(or squads in your situation) the client fires a RemoteEvent and the server creates a table with the code. Now if a player types a code to join a squad, the client fires a RemoteEvent telling the server the code and then the server finds a squad with the same code and enters them.
--server side
local rs = game:GetService("ReplicatedStorage")
local signal = rs:WaitForChild("squad")
local squads = {}
signal.ClientInvoke:Connect(function(player, code)
local plrName = player.Name
if squads[code] then
table.insert(squads[code], plrName)
--added
else
table.insert(squads, table.create(code, plr.Name))
--newTable
end
end)
--local side
local player = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local signal = rs:WaitForChild("squad")
player.PlayerGui.Squadenter.Textbox.Changed:Connect(function()
local text = player.PlayerGui.Squadenter.Textbox.Text
--add char tests to make sure it is characters
-- CHANGE TO A CONFIRM SYSTEM
if string.len(text) == 4 then
signal.InvokeServer(text) --remote functions send player automatically
end
end)
This is how you would see the squad code and read it. As AlbertSeir said you should do a remote event because it will be safer in the case of an error but this is the general gist of it. This is a quick type up so it will error but I think this will point you in the right direction.