Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local part = script.Parent
- local textLabel = part:WaitForChild("SurfaceGui"):WaitForChild("TextLabel")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local CheckSecretCode = ReplicatedStorage:WaitForChild("CheckSecretCode")
- -- Настройки
- local CODE_LENGTH = 8
- -- Английские буквы + цифры
- local characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
- -- Генерация случайного кода
- local function generateCode(length)
- local code = ""
- for i = 1, length do
- local randomIndex = math.random(1, #characters)
- code = code .. string.sub(characters, randomIndex, randomIndex)
- end
- return code
- end
- -- Генерируем код
- local secretCode = generateCode(CODE_LENGTH)
- -- Показываем его в TextLabel
- textLabel.Text = secretCode
- -- Настройки TextLabel
- textLabel.Font = Enum.Font.Code
- textLabel.TextScaled = true
- print("Сгенерированный код:", secretCode)
- -- Проверка введённого игроком кода
- CheckSecretCode.OnServerEvent:Connect(function(player, enteredCode)
- -- Убираем случайные пробелы по краям
- enteredCode = string.gsub(enteredCode, "^%s+", "")
- enteredCode = string.gsub(enteredCode, "%s+$", "")
- -- Проверяем код
- local isCorrect = enteredCode == secretCode
- -- Отправляем результат обратно игроку
- CheckSecretCode:FireClient(player, isCorrect)
- end)
Advertisement
Add Comment
Please, Sign In to add comment