Hasli4

Untitled

Aug 30th, 2026
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local TextService = game:GetService("TextService")
  4.  
  5. --------------------------------------------------
  6. -- RemoteEvents
  7. --------------------------------------------------
  8.  
  9. local openNameInput = ReplicatedStorage:WaitForChild("OpenNameInput")
  10. local submitPlayerName = ReplicatedStorage:WaitForChild("SubmitPlayerName")
  11. local showDialogResponse = ReplicatedStorage:WaitForChild("ShowDialogResponse")
  12.  
  13.  
  14. --------------------------------------------------
  15. -- Dialog
  16. --------------------------------------------------
  17.  
  18. local dialog = workspace.NPC.Head.Dialog
  19. local nameChoice = dialog:WaitForChild("NameChoice")
  20.  
  21.  
  22. --------------------------------------------------
  23. -- Имена игроков
  24. --
  25. -- Ключ = UserId
  26. -- Значение = введённое имя
  27. --
  28. -- Эти данные находятся только на сервере.
  29. --------------------------------------------------
  30.  
  31. local playerNames = {}
  32.  
  33.  
  34. --------------------------------------------------
  35. -- Игрок выбрал "Меня зовут..."
  36. --------------------------------------------------
  37.  
  38. dialog.DialogChoiceSelected:Connect(function(player, choice)
  39.  
  40. -- Нас интересует только NameChoice
  41. if choice ~= nameChoice then
  42. return
  43. end
  44.  
  45. -- Открываем окно только этому игроку
  46. openNameInput:FireClient(player)
  47.  
  48. end)
  49.  
  50.  
  51. --------------------------------------------------
  52. -- Игрок отправил имя
  53. --------------------------------------------------
  54.  
  55. submitPlayerName.OnServerEvent:Connect(function(player, rawName)
  56.  
  57. --------------------------------------------------
  58. -- Проверяем тип данных
  59. --------------------------------------------------
  60.  
  61. if typeof(rawName) ~= "string" then
  62. return
  63. end
  64.  
  65.  
  66. --------------------------------------------------
  67. -- Убираем пробелы
  68. --------------------------------------------------
  69.  
  70. rawName = rawName:match("^%s*(.-)%s*$")
  71.  
  72.  
  73. --------------------------------------------------
  74. -- Пустое имя
  75. --------------------------------------------------
  76.  
  77. if rawName == "" then
  78. return
  79. end
  80.  
  81.  
  82. --------------------------------------------------
  83. -- Ограничиваем длину
  84. --------------------------------------------------
  85.  
  86. local nameLength = utf8.len(rawName)
  87.  
  88. if not nameLength then
  89. return
  90. end
  91.  
  92. if nameLength > 20 then
  93. local position = utf8.offset(rawName, 21)
  94.  
  95. if position then
  96. rawName = string.sub(rawName, 1, position - 1)
  97. end
  98. end
  99.  
  100.  
  101. --------------------------------------------------
  102. -- Фильтрация текста
  103. --------------------------------------------------
  104.  
  105. local success, filterResult = pcall(function()
  106.  
  107. return TextService:FilterStringAsync(
  108. rawName,
  109. player.UserId
  110. )
  111.  
  112. end)
  113.  
  114.  
  115. if not success then
  116.  
  117. warn(
  118. "Не удалось отфильтровать имя:",
  119. player.Name
  120. )
  121.  
  122. return
  123. end
  124.  
  125.  
  126. --------------------------------------------------
  127. -- Получаем текст, который можно показать
  128. -- этому игроку
  129. --------------------------------------------------
  130.  
  131. local successFiltered, filteredName = pcall(function()
  132.  
  133. return filterResult:GetNonChatStringForUserAsync(
  134. player.UserId
  135. )
  136.  
  137. end)
  138.  
  139.  
  140. if not successFiltered then
  141.  
  142. warn(
  143. "Не удалось получить отфильтрованное имя:",
  144. player.Name
  145. )
  146.  
  147. return
  148. end
  149.  
  150.  
  151. --------------------------------------------------
  152. -- Дополнительная проверка
  153. --------------------------------------------------
  154.  
  155. if typeof(filteredName) ~= "string" then
  156. return
  157. end
  158.  
  159. if filteredName == "" then
  160. return
  161. end
  162.  
  163.  
  164. --------------------------------------------------
  165. -- Сохраняем имя КОНКРЕТНОГО игрока
  166. --------------------------------------------------
  167.  
  168. playerNames[player.UserId] = filteredName
  169.  
  170.  
  171. print(
  172. "Имя персонажа:",
  173. player.Name,
  174. "→",
  175. filteredName
  176. )
  177.  
  178.  
  179. --------------------------------------------------
  180. -- Формируем персональный ответ
  181. --------------------------------------------------
  182.  
  183. local response =
  184. "Понятно, " .. filteredName .. "."
  185.  
  186.  
  187. --------------------------------------------------
  188. -- Отправляем ответ ТОЛЬКО этому игроку
  189. --------------------------------------------------
  190.  
  191. showDialogResponse:FireClient(
  192. player,
  193. response
  194. )
  195.  
  196. end)
  197.  
  198.  
  199. --------------------------------------------------
  200. -- Игрок вышел
  201. --------------------------------------------------
  202.  
  203. Players.PlayerRemoving:Connect(function(player)
  204.  
  205. playerNames[player.UserId] = nil
  206.  
  207. end)
Advertisement
Add Comment
Please, Sign In to add comment