Zulkin

Hitbox Expander

Oct 21st, 2021 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.40 KB | None | 0 0
  1. -- Credits to Rex (C/E)#9115
  2. -- Global Hitbox Expander (Players & NPCs)
  3. -- I'm not gonna make this a GUI because it'll be easier to patch, sorry :(
  4. -- Updated 2/5/2022, Exact time 1:04 AM PST
  5. -- Update: Major overhaul. Changed the sussy chat variant to the least sussy keybind version. Additionally made it so that this script has a passive nocollide for all players and npcs (experimental)
  6.  
  7. local players = game:GetService("Players")
  8. local plr = players.LocalPlayer
  9. local mouse = plr:GetMouse()
  10. local workspace = game:GetService("Workspace")
  11. local Size = 5 -- Change this number to the stud range in width, length, and height you want it to be. One number because its used for all axis.
  12. local Repeat = true -- Change it to make it repeat or not (if its repeating, it might lag a bit. but manually changing it can be annoying too)
  13. local RenderStepped = game:GetService("RunService").RenderStepped -- Dont mess with this
  14. local PhysicsService = game:GetService("PhysicsService") -- Dont mess with this
  15. local EnableWithHotkey = true -- Enable Hotkey
  16. local NonExpandingHeadSize = 1 -- For when you arent expanding
  17. local NPCSArea = workspace -- Where to get NPCS
  18. local PlayersArea = workspace -- Where to get Players
  19. local KeyToEnable = "[" -- The hotkey to begin expanding
  20. local NPCExtend = false -- Weather or not to hitbox expand none player entities
  21. local PlayerExtend = true -- Weather or not to hitbox extend player characters
  22. local ResetHeadsOnDisable = true -- Resets the heads back to their non expanding sizes. Temporary feature.
  23. local RepeatCooldown = 5
  24. local Debounce = false
  25. local ExpandPart = "Head"
  26.  
  27. ------------------------------------- !!DISABLED Simple No Collisions DISABLED!! ---------------------------------
  28. --[[
  29. local playerCollisionGroupName = "Entities"
  30. PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
  31. PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)
  32.  
  33. local previousCollisionGroups = {}
  34.  
  35. local function setCollisionGroup(object)
  36.     if object:IsA("BasePart") then
  37.         previousCollisionGroups[object] = object.CollisionGroupId
  38.         PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
  39.     end
  40. end
  41.  
  42. local function setCollisionGroupRecursive(object)
  43.     setCollisionGroup(object)
  44.  
  45.     for _, child in ipairs(object:GetChildren()) do
  46.         setCollisionGroupRecursive(child)
  47.     end
  48. end
  49.  
  50. local function resetCollisionGroup(object)
  51.     local previousCollisionGroupId = previousCollisionGroups[object]
  52.     if not previousCollisionGroupId then return end
  53.  
  54.     local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
  55.     if not previousCollisionGroupName then return end
  56.  
  57.     PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
  58.     previousCollisionGroups[object] = nil
  59. end
  60.  
  61. local function onCharacterAdded(character)
  62.     setCollisionGroupRecursive(character)
  63.  
  64.     character.DescendantAdded:Connect(setCollisionGroup)
  65.     character.DescendantRemoving:Connect(resetCollisionGroup)
  66. end
  67.  
  68. local function onPlayerAdded(player)
  69.     player.CharacterAdded:Connect(onCharacterAdded)
  70. end
  71.  
  72. players.PlayerAdded:Connect(onPlayerAdded)
  73. NPCSArea.ChildAdded:Connect(function(yes)
  74.     if yes:IsA("Model") and yes:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(yes) then
  75.         onCharacterAdded(yes)
  76.     end
  77. end)
  78. for i,v in ipairs(NPCSArea:GetDescendants()) do
  79.     if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(v) then
  80.         onCharacterAdded(v)
  81.     end
  82. end
  83. PlayersArea.ChildAdded:Connect(function(yes)
  84.     if yes:IsA("Model") and yes:FindFirstChildOfClass("Humanoid") and players:GetPlayerFromCharacter(yes) then
  85.         onCharacterAdded(yes)
  86.     end
  87. end)
  88. for i,v in ipairs(PlayersArea:GetDescendants()) do
  89.     if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") and players:GetPlayerFromCharacter(v) then
  90.         onCharacterAdded(v)
  91.     end
  92. end
  93. ]]
  94. ----------------------------------------------- Key Presses -------------------------------------------
  95.  
  96. mouse.KeyDown:Connect(function(Key)
  97.     if Key == KeyToEnable then
  98.         print("Pressed")
  99.         Repeat = not Repeat
  100.     end
  101. end)
  102.  
  103. ----------------------------------------------- Main Code ---------------------------------------------
  104.  
  105.  
  106. if Repeat then
  107.     print("Repeating")
  108.     RenderStepped:Connect(function()
  109.         if Repeat and not Debounce then
  110.             children = workspace:GetDescendants()
  111.             entities = players:GetChildren()
  112.             while Repeat do
  113.                 print("Expanding")
  114.                 Debounce = true
  115.                 children = workspace:GetDescendants()
  116.                 entities = players:GetChildren()
  117.                 wait(RepeatCooldown)
  118.                 if PlayerExtend then
  119.                     for i,v in pairs(entities) do
  120.                         if v.Name ~= players.LocalPlayer.Name then
  121.                             v.Character:WaitForChild(ExpandPart).Size = Vector3.new(Size,Size,Size)
  122.                         end
  123.                     end
  124.                 end
  125.                 if NPCExtend then
  126.                     for i,v in pairs(children) do
  127.                         if v.Name == ExpandPart and v.Parent:IsA("Model") and v.Parent:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(v.Parent) then
  128.                             v.Size = Vector3.new(Size,Size,Size)
  129.                         end
  130.                     end
  131.                 end
  132.             end
  133.             children = workspace:GetDescendants()
  134.             entities = players:GetChildren()
  135.             if PlayerExtend then
  136.                 for i,v in pairs(entities) do
  137.                     if v.Name ~= players.LocalPlayer.Name then
  138.                         v.Character:WaitForChild(ExpandPart).Size = Vector3.new(NonExpandingHeadSize,NonExpandingHeadSize,NonExpandingHeadSize)
  139.                     end
  140.                 end
  141.             end
  142.             if NPCExtend then
  143.                 for i,v in pairs(children) do
  144.                     if v.Name == ExpandPart and v.Parent:IsA("Model") and v.Parent:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(v.Parent) then
  145.                         v.Size = Vector3.new(NonExpandingHeadSize,NonExpandingHeadSize,NonExpandingHeadSize)
  146.                     end
  147.                 end
  148.             end
  149.             Debounce = false
  150.         end
  151.         if not Repeat and not Debounce then
  152.             print("Disabled")
  153.             children = workspace:GetDescendants()
  154.             entities = players:GetChildren()
  155.             while not Repeat do
  156.                 Debounce = true
  157.                 children = workspace:GetDescendants()
  158.                 entities = players:GetChildren()
  159.                 wait(RepeatCooldown)
  160.                 if PlayerExtend then
  161.                     for i,v in pairs(entities) do
  162.                         if v.Name ~= players.LocalPlayer.Name then
  163.                             v.Character:WaitForChild(ExpandPart).Size = Vector3.new(NonExpandingHeadSize,NonExpandingHeadSize,NonExpandingHeadSize)
  164.                         end
  165.                     end
  166.                 end
  167.                 if NPCExtend then
  168.                     for i,v in pairs(children) do
  169.                         if v.Name == ExpandPart and v.Parent:IsA("Model") and v.Parent:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(v.Parent) then
  170.                             v.Size = Vector3.new(NonExpandingHeadSize,NonExpandingHeadSize,NonExpandingHeadSize)
  171.                         end
  172.                     end
  173.                 end
  174.             end
  175.             children = workspace:GetDescendants()
  176.             entities = players:GetChildren()
  177.             Debounce = false
  178.         end
  179.     end)
  180. else
  181.     children = workspace:GetDescendants()
  182.     entities = players:GetChildren()
  183.     if PlayerExtend then
  184.         for i,v in pairs(entities) do
  185.             if v.Name ~= players.LocalPlayer.Name then
  186.                 v.Character:WaitForChild(ExpandPart).Size = Vector3.new(Size,Size,Size)
  187.             end
  188.         end
  189.     end
  190.     if NPCExtend then
  191.         for i,v in pairs(children) do
  192.             if v.Name == ExpandPart and v.Parent:IsA("Model") and v.Parent:FindFirstChildOfClass("Humanoid") and not players:GetPlayerFromCharacter(v.Parent) then
  193.                 v.Size = Vector3.new(Size,Size,Size)
  194.             end
  195.         end
  196.     end
  197. end
  198.  
  199.  
  200. ------------------------------------------- End of Script -------------------------------------------
  201.  
Add Comment
Please, Sign In to add comment