I’m making a private match system where the module script will create a match code and store it in a table. When the player wants to join a match, the module script will check if there is a match in the matches table with the code that they inputted. If it is, then the player joins the match. The problem is, however, the script thinks the code that the player inputted and the existing match code aren’t the same.
Here is the module script:
local funcs = {}
local matches = {}
function funcs:GetMatches()
return matches
end
function funcs:FindMatch(Code)
local found = false
if matches[tonumber(Code)] == nil then
found = true
else
found = true
end
return found
end
function funcs:CreateMatch(player)
local code = tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9))
matches[code] = {}
matches[code][player.Name] = "Host"
return code
end
function funcs:JoinMatch(player,code)
if matches[tonumber(code)] == nil then
warn("Invalid Match Code")
else
matches[tonumber(code)][player.Name] = "Player"
for name,role in pairs(matches[tonumber(code)]) do
if role == "Host" then
local plr = game.Players:FindFirstChild(name)
local temp = script.PlayerTemp:Clone()
temp.Name = name
temp.ImageLabel.Image = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.AvatarBust,Enum.ThumbnailSize.Size100x100)
temp.PlayerName.Text = name
temp.Parent = plr.PlayerGui.Menu.MatchHostFrame.PlayersFrame
break
end
end
end
end
Thanks for reading ![]()