Hasli4

Untitled

Aug 29th, 2026
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local TextService = game:GetService("TextService")
  4.  
  5. local openNameInput = ReplicatedStorage:WaitForChild("OpenNameInput")
  6. local submitPlayerName = ReplicatedStorage:WaitForChild("SubmitPlayerName")
  7.  
  8. local dialog = workspace.NPC.Head.Dialog
  9. local nameChoice = dialog:WaitForChild("NameChoice")
  10.  
  11. -- Имя хранится ТОЛЬКО на сервере.
  12. -- Ключ = UserId игрока.
  13. local playerNames = {}
  14.  
  15. --------------------------------------------------
  16. -- Игрок выбрал "Меня зовут..."
  17. --------------------------------------------------
  18.  
  19. dialog.DialogChoiceSelected:Connect(function(player, choice)
  20.  
  21. if choice ~= nameChoice then
  22. return
  23. end
  24.  
  25. -- Открываем окно только этому игроку
  26. openNameInput:FireClient(player)
  27. end)
  28.  
  29. --------------------------------------------------
  30. -- Игрок отправил имя
  31. --------------------------------------------------
  32.  
  33. submitPlayerName.OnServerEvent:Connect(function(player, rawName)
  34.  
  35. -- Защита от неправильных данных
  36. if typeof(rawName) ~= "string" then
  37. return
  38. end
  39.  
  40. -- Убираем пробелы по краям
  41. rawName = rawName:match("^%s*(.-)%s*$")
  42.  
  43. -- Пустое имя
  44. if rawName == "" then
  45. return
  46. end
  47.  
  48. -- Ограничиваем длину
  49. if #rawName > 20 then
  50. rawName = string.sub(rawName, 1, 20)
  51. end
  52.  
  53. --------------------------------------------------
  54. -- Фильтрация пользовательского текста
  55. --------------------------------------------------
  56.  
  57. local success, result = pcall(function()
  58.  
  59. local filterResult = TextService:FilterStringAsync(
  60. rawName,
  61. player.UserId
  62. )
  63.  
  64. return filterResult:GetNonChatStringForUserAsync(player.UserId)
  65.  
  66. end)
  67.  
  68. if not success then
  69. warn("Не удалось отфильтровать имя игрока:", result)
  70. return
  71. end
  72.  
  73. local filteredName = result
  74.  
  75. --------------------------------------------------
  76. -- Сохраняем имя конкретного игрока
  77. --------------------------------------------------
  78.  
  79. playerNames[player.UserId] = filteredName
  80.  
  81. print(
  82. player.Name ..
  83. " теперь имеет имя персонажа: " ..
  84. filteredName
  85. )
  86.  
  87. --------------------------------------------------
  88. -- Возвращаем результат только этому игроку
  89. --------------------------------------------------
  90.  
  91. openNameInput:FireClient(
  92. player,
  93. "Понятно, " .. filteredName
  94. )
  95. end)
  96.  
  97. --------------------------------------------------
  98. -- Удаляем данные, когда игрок выходит
  99. --------------------------------------------------
  100.  
  101. Players.PlayerRemoving:Connect(function(player)
  102. playerNames[player.UserId] = nil
  103. end)
Advertisement
Add Comment
Please, Sign In to add comment