How would I make a code system

Okay so in my game you can create squads, and when you do, it makes a 4 random string of letters (ex. JQSW).

Lets say there are 3 squads

First squad’s code is = UJEQ
Second squad’s code is = MPVB
Third squad’s code is = KWBZ

lets say i want to join the second squad, so i put MPVB. how would i tell the server the code i put belongs to the second squad?

Feel free to ask any questions

do a remote event for this, then check the code with a if statement ( and if theyre not already in a squad )

There are a couple of ways. So you could have a button or gui to press to lock in the code and that would look like this.

	local code = player.PlayerGui.Squadenter.Textbox.Text 
        if code == "MPVB" then


You could have different if statements for different codes.

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)
		table.insert(squads, table.create(code, plr.Name))

--local side
local player = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local signal = rs:WaitForChild("squad")

	local text = player.PlayerGui.Squadenter.Textbox.Text 
	--add char tests to make sure it is characters
	if string.len(text) == 4 then
		signal.InvokeServer(text) --remote functions send player automatically

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.