Meliodas0_0

Name-Protect

Sep 9th, 2019
36
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Name Protect Script by 3dsboy08
  2.  
  3. local Config =
  4. {
  5. ProtectedName = "NameProtect", --What the protected name should be called.
  6. OtherPlayers = true, --If other players should also have protected names.
  7. OtherPlayersTemplate = "NameProtect", --Template for other players protected name (ex: "NamedProtect" will turn into "NameProtect1" for first player and so on)
  8. RenameTextBoxes = false, --If TextBoxes should be renamed. (could cause issues with admin guis/etc)
  9. UseFilterPadding = false, --If filtered name should be the same size as a regular name.
  10. FilterPad = " ", --Character used to filter pad.
  11. UseMetatableHook = true, --Use metatable hook to increase chance of filtering. (is not supported on wrappers like bleu)
  12. UseAggressiveFiltering = false --Use aggressive property renaming filter. (renames a lot more but at the cost of lag)
  13. }
  14.  
  15. local ProtectedNames = {}
  16. local Counter = 1
  17. if Config.OtherPlayers then
  18. for I, V in pairs(game:GetService("Players"):GetPlayers()) do
  19. local Filter = Config.OtherPlayersTemplate .. tostring(Counter)
  20. if Config.UseFilterPadding then
  21. if string.len(Filter) > string.len(V.Name) then
  22. Filter = string.sub(Filter, 1, string.len(V.Name))
  23. elseif string.len(Filter) < string.len(V.Name) then
  24. local Add = string.len(V.Name) - string.len(Filter)
  25. for I=1,Add do
  26. Filter = Filter .. Config.FilterPad
  27. end
  28. end
  29. end
  30. ProtectedNames[V.Name] = Filter
  31. Counter = Counter + 1
  32. end
  33.  
  34. game:GetService("Players").PlayerAdded:connect(function(Player)
  35. local Filter = Config.OtherPlayersTemplate .. tostring(Counter)
  36. if Config.UseFilterPadding then
  37. if string.len(Filter) > string.len(V.Name) then
  38. Filter = string.sub(Filter, 1, string.len(V.Name))
  39. elseif string.len(Filter) < string.len(V.Name) then
  40. local Add = string.len(V.Name) - string.len(Filter)
  41. for I=1,Add do
  42. Filter = Filter .. Config.FilterPad
  43. end
  44. end
  45. end
  46. ProtectedNames[Player.Name] = Filter
  47. Counter = Counter + 1
  48. end)
  49. end
  50.  
  51. local LPName = game:GetService("Players").LocalPlayer.Name
  52. local IsA = game.IsA
  53.  
  54. if Config.UseFilterPadding then
  55. if string.len(Config.ProtectedName) > string.len(LPName) then
  56. Config.ProtectedName = string.sub(Config.ProtectedName, 1, string.len(LPName))
  57. elseif string.len(Config.ProtectedName) < string.len(LPName) then
  58. local Add = string.len(LPName) - string.len(Config.ProtectedName)
  59. for I=1,Add do
  60. Config.ProtectedName = Config.ProtectedName .. Config.FilterPad
  61. end
  62. end
  63. end
  64.  
  65. local function FilterString(S)
  66. local RS = S
  67. if Config.OtherPlayers then
  68. for I, V in pairs(ProtectedNames) do
  69. RS = string.gsub(RS, I, V)
  70. end
  71. end
  72. RS = string.gsub(RS, LPName, Config.ProtectedName)
  73. return RS
  74. end
  75.  
  76. for I, V in pairs(game:GetDescendants()) do
  77. if Config.RenameTextBoxes then
  78. if IsA(V, "TextLabel") or IsA(V, "TextButton") or IsA(V, "TextBox") then
  79. V.Text = FilterString(V.Text)
  80.  
  81. if Config.UseAggressiveFiltering then
  82. V:GetPropertyChangedSignal("Text"):connect(function()
  83. V.Text = FilterString(V.Text)
  84. end)
  85. end
  86. end
  87. else
  88. if IsA(V, "TextLabel") or IsA(V, "TextButton") then
  89. V.Text = FilterString(V.Text)
  90.  
  91. if Config.UseAggressiveFiltering then
  92. V:GetPropertyChangedSignal("Text"):connect(function()
  93. V.Text = FilterString(V.Text)
  94. end)
  95. end
  96. end
  97. end
  98. end
  99.  
  100. if Config.UseAggressiveFiltering then
  101. game.DescendantAdded:connect(function(V)
  102. if Config.RenameTextBoxes then
  103. if IsA(V, "TextLabel") or IsA(V, "TextButton") or IsA(V, "TextBox") then
  104. V:GetPropertyChangedSignal("Text"):connect(function()
  105. V.Text = FilterString(V.Text)
  106. end)
  107. end
  108. else
  109. if IsA(V, "TextLabel") or IsA(V, "TextButton") then
  110. V:GetPropertyChangedSignal("Text"):connect(function()
  111. V.Text = FilterString(V.Text)
  112. end)
  113. end
  114. end
  115. end)
  116. end
  117.  
  118. if Config.UseMetatableHook then
  119. if not getrawmetatable then
  120. error("GetRawMetaTable not found")
  121. end
  122.  
  123. local NewCC = function(F)
  124. if newcclosure then return newcclosure(F) end
  125. return F
  126. end
  127.  
  128. local SetRO = function(MT, V)
  129. if setreadonly then return setreadonly(MT, V) end
  130. if not V and make_writeable then return make_writeable(MT) end
  131. if V and make_readonly then return make_readonly(MT) end
  132. error("No setreadonly found")
  133. end
  134.  
  135. local MT = getrawmetatable(game)
  136. local OldNewIndex = MT.__newindex
  137. SetRO(MT, false)
  138.  
  139. MT.__newindex = NewCC(function(T, K, V)
  140. if Config.RenameTextBoxes then
  141. if (IsA(T, "TextLabel") or IsA(T, "TextButton") or IsA(T, "TextBox")) and K == "Text" and type(V) == "string" then
  142. return OldNewIndex(T, K, FilterString(V))
  143. end
  144. else
  145. if (IsA(T, "TextLabel") or IsA(T, "TextButton")) and K == "Text" and type(V) == "string" then
  146. return OldNewIndex(T, K, FilterString(V))
  147. end
  148. end
  149.  
  150. return OldNewIndex(T, K, V)
  151. end)
  152.  
  153. SetRO(MT, true)
  154. end
RAW Paste Data