Hasli4

Untitled

Aug 12th, 2026
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1.  
  2. local Players = game:GetService("Players")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4.  
  5. local GetSecretCode = ReplicatedStorage:WaitForChild("GetSecretCode")
  6. local CheckSecretCode = ReplicatedStorage:WaitForChild("CheckSecretCode")
  7.  
  8.  
  9. -- =====================================================
  10. -- НАСТРОЙКИ
  11. -- =====================================================
  12.  
  13. local CODE_LENGTH = 8
  14.  
  15. -- Английские буквы + цифры
  16. local CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  17.  
  18.  
  19. -- =====================================================
  20. -- ТАБЛИЦА КОДОВ ИГРОКОВ
  21. -- =====================================================
  22.  
  23. local playerCodes = {}
  24.  
  25.  
  26. -- =====================================================
  27. -- ГЕНЕРАЦИЯ СЛУЧАЙНОГО КОДА
  28. -- =====================================================
  29.  
  30. local function generateCode(length)
  31.  
  32. local code = ""
  33.  
  34. for i = 1, length do
  35.  
  36. local randomIndex = math.random(1, #CHARACTERS)
  37.  
  38. local randomCharacter =
  39. string.sub(CHARACTERS, randomIndex, randomIndex)
  40.  
  41. code = code .. randomCharacter
  42.  
  43. end
  44.  
  45. return code
  46.  
  47. end
  48.  
  49.  
  50. -- =====================================================
  51. -- КОГДА ИГРОК ЗАХОДИТ
  52. -- =====================================================
  53.  
  54. Players.PlayerAdded:Connect(function(player)
  55.  
  56. local newCode = generateCode(CODE_LENGTH)
  57.  
  58. playerCodes[player.UserId] = newCode
  59.  
  60. print(
  61. "Игрок:",
  62. player.Name,
  63. "| Его код:",
  64. newCode
  65. )
  66.  
  67. end)
  68.  
  69.  
  70. -- =====================================================
  71. -- КОГДА ИГРОК ВЫХОДИТ
  72. -- =====================================================
  73.  
  74. Players.PlayerRemoving:Connect(function(player)
  75.  
  76. playerCodes[player.UserId] = nil
  77.  
  78. end)
  79.  
  80.  
  81. -- =====================================================
  82. -- ПОЛУЧЕНИЕ КОДА ИГРОКОМ
  83. -- =====================================================
  84.  
  85. GetSecretCode.OnServerInvoke = function(player)
  86.  
  87. local code = playerCodes[player.UserId]
  88.  
  89. return code
  90.  
  91. end
  92.  
  93.  
  94. -- =====================================================
  95. -- ПРОВЕРКА ВВЕДЁННОГО КОДА
  96. -- =====================================================
  97.  
  98. CheckSecretCode.OnServerEvent:Connect(function(player, enteredCode)
  99.  
  100. -- Получаем настоящий код именно этого игрока
  101. local correctCode = playerCodes[player.UserId]
  102.  
  103. if not correctCode then
  104. return
  105. end
  106.  
  107.  
  108. -- Проверяем, что пришла строка
  109. if typeof(enteredCode) ~= "string" then
  110. return
  111. end
  112.  
  113.  
  114. -- Убираем пробелы в начале и конце
  115. enteredCode = string.gsub(
  116. enteredCode,
  117. "^%s+",
  118. ""
  119. )
  120.  
  121. enteredCode = string.gsub(
  122. enteredCode,
  123. "%s+$",
  124. ""
  125. )
  126.  
  127.  
  128. -- Сравнение
  129. local isCorrect = enteredCode == correctCode
  130.  
  131.  
  132. -- Отправляем результат только этому игроку
  133. CheckSecretCode:FireClient(
  134. player,
  135. isCorrect
  136. )
  137.  
  138. end)
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment