Cakey3101

Hitbox Module - 11

Sep 2nd, 2025
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | Source Code | 0 0
  1. local Workspace = game:GetService("Workspace")
  2. local RunService = game:GetService("RunService")
  3.  
  4. HitboxModule = {}
  5.  
  6. function HitboxModule.CreateHitbox(Player: Player, Mode: string, Size: Vector3, Pos: Vector3)
  7.     local Character = Player.Character or Player.CharacterAdded:Wait()
  8.     if not Character or not Character.PrimaryPart then
  9.         return nil
  10.     end
  11.    
  12.     local Hitbox = Instance.new("Part")
  13.     Hitbox.Anchored = false
  14.     Hitbox.CanCollide = false
  15.     Hitbox.Transparency = 0.5
  16.     Hitbox.Size = Vector3.new(Size.X, Size.Y, Size.Z)
  17.     Hitbox.Color = Color3.fromRGB(255, 0, 0)
  18.    
  19.     local FrontPosition = Character.PrimaryPart.CFrame * CFrame.new(0, 0, (Size.Z / 2 + 0.5))
  20.    
  21.     if Mode == "Sphere" then
  22.         Hitbox.Shape = Enum.PartType.Ball
  23.         Hitbox.Size = Vector3.new(Size.X, Size.Y, Size.Z)
  24.         Hitbox.CFrame = Pos or FrontPosition
  25.     elseif Mode == "Block" then
  26.         Hitbox.Shape = Enum.PartType.Block
  27.         Hitbox.CFrame = Pos or FrontPosition
  28.     elseif Mode == "Cylinder" then
  29.         Hitbox.Shape = Enum.PartType.Cylinder
  30.         Hitbox.Orientation = Vector3.new(90, 0, 0)
  31.         Hitbox.CFrame = Pos or FrontPosition
  32.     elseif Mode == "SphereCenter" then
  33.         Hitbox.Shape = Enum.PartType.Ball
  34.         Hitbox.CFrame = Pos or Character.PrimaryPart.CFrame
  35.     elseif Mode == "BlockCenter" then
  36.         Hitbox.Shape = Enum.PartType.Block
  37.         Hitbox.CFrame = Pos or Character.PrimaryPart.CFrame
  38.     end
  39.    
  40.     Hitbox.Parent = Workspace
  41.  
  42.     local function UpdateHitboxPosition()
  43.         if Hitbox and Character.PrimaryPart then
  44.             local HRP: BasePart = Character:FindFirstChild("HumanoidRootPart")
  45.            
  46.             if Pos then
  47.                 Hitbox.CFrame = Pos
  48.             elseif Mode:find("Center") then
  49.                 Hitbox.CFrame = Character.PrimaryPart.CFrame
  50.             else
  51.                 local FrontOffset = HRP.CFrame.LookVector * (Size.Z / 2 + 0.5)
  52.                 Hitbox.CFrame = CFrame.new(HRP.Position + FrontOffset, HRP.Position + FrontOffset + HRP.CFrame.LookVector)
  53.             end
  54.         end
  55.     end
  56.    
  57.     local Connection
  58.    
  59.     Connection = RunService.PostSimulation:Connect(function()
  60.         if not Character or not Character:IsDescendantOf(Workspace) then
  61.             Connection:Disconnect()
  62.         else
  63.             UpdateHitboxPosition()
  64.         end
  65.     end)
  66.    
  67.     return Hitbox
  68. end
  69.  
  70. return HitboxModule
Advertisement
Add Comment
Please, Sign In to add comment