Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local TextService = game:GetService("TextService")
- local openNameInput = ReplicatedStorage:WaitForChild("OpenNameInput")
- local submitPlayerName = ReplicatedStorage:WaitForChild("SubmitPlayerName")
- local dialog = workspace.NPC.Head.Dialog
- local nameChoice = dialog:WaitForChild("NameChoice")
- -- Имя хранится ТОЛЬКО на сервере.
- -- Ключ = UserId игрока.
- local playerNames = {}
- --------------------------------------------------
- -- Игрок выбрал "Меня зовут..."
- --------------------------------------------------
- dialog.DialogChoiceSelected:Connect(function(player, choice)
- if choice ~= nameChoice then
- return
- end
- -- Открываем окно только этому игроку
- openNameInput:FireClient(player)
- end)
- --------------------------------------------------
- -- Игрок отправил имя
- --------------------------------------------------
- submitPlayerName.OnServerEvent:Connect(function(player, rawName)
- -- Защита от неправильных данных
- if typeof(rawName) ~= "string" then
- return
- end
- -- Убираем пробелы по краям
- rawName = rawName:match("^%s*(.-)%s*$")
- -- Пустое имя
- if rawName == "" then
- return
- end
- -- Ограничиваем длину
- if #rawName > 20 then
- rawName = string.sub(rawName, 1, 20)
- end
- --------------------------------------------------
- -- Фильтрация пользовательского текста
- --------------------------------------------------
- local success, result = pcall(function()
- local filterResult = TextService:FilterStringAsync(
- rawName,
- player.UserId
- )
- return filterResult:GetNonChatStringForUserAsync(player.UserId)
- end)
- if not success then
- warn("Не удалось отфильтровать имя игрока:", result)
- return
- end
- local filteredName = result
- --------------------------------------------------
- -- Сохраняем имя конкретного игрока
- --------------------------------------------------
- playerNames[player.UserId] = filteredName
- print(
- player.Name ..
- " теперь имеет имя персонажа: " ..
- filteredName
- )
- --------------------------------------------------
- -- Возвращаем результат только этому игроку
- --------------------------------------------------
- openNameInput:FireClient(
- player,
- "Понятно, " .. filteredName
- )
- end)
- --------------------------------------------------
- -- Удаляем данные, когда игрок выходит
- --------------------------------------------------
- Players.PlayerRemoving:Connect(function(player)
- playerNames[player.UserId] = nil
- end)
Advertisement
Add Comment
Please, Sign In to add comment