Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Workspace = game:GetService("Workspace")
- local RunService = game:GetService("RunService")
- HitboxModule = {}
- function HitboxModule.CreateHitbox(Player: Player, Mode: string, Size: Vector3, Pos: Vector3)
- local Character = Player.Character or Player.CharacterAdded:Wait()
- if not Character or not Character.PrimaryPart then
- return nil
- end
- local Hitbox = Instance.new("Part")
- Hitbox.Anchored = false
- Hitbox.CanCollide = false
- Hitbox.Transparency = 0.5
- Hitbox.Size = Vector3.new(Size.X, Size.Y, Size.Z)
- Hitbox.Color = Color3.fromRGB(255, 0, 0)
- local FrontPosition = Character.PrimaryPart.CFrame * CFrame.new(0, 0, (Size.Z / 2 + 0.5))
- if Mode == "Sphere" then
- Hitbox.Shape = Enum.PartType.Ball
- Hitbox.Size = Vector3.new(Size.X, Size.Y, Size.Z)
- Hitbox.CFrame = Pos or FrontPosition
- elseif Mode == "Block" then
- Hitbox.Shape = Enum.PartType.Block
- Hitbox.CFrame = Pos or FrontPosition
- elseif Mode == "Cylinder" then
- Hitbox.Shape = Enum.PartType.Cylinder
- Hitbox.Orientation = Vector3.new(90, 0, 0)
- Hitbox.CFrame = Pos or FrontPosition
- elseif Mode == "SphereCenter" then
- Hitbox.Shape = Enum.PartType.Ball
- Hitbox.CFrame = Pos or Character.PrimaryPart.CFrame
- elseif Mode == "BlockCenter" then
- Hitbox.Shape = Enum.PartType.Block
- Hitbox.CFrame = Pos or Character.PrimaryPart.CFrame
- end
- Hitbox.Parent = Workspace
- local function UpdateHitboxPosition()
- if Hitbox and Character.PrimaryPart then
- local HRP: BasePart = Character:FindFirstChild("HumanoidRootPart")
- if Pos then
- Hitbox.CFrame = Pos
- elseif Mode:find("Center") then
- Hitbox.CFrame = Character.PrimaryPart.CFrame
- else
- local FrontOffset = HRP.CFrame.LookVector * (Size.Z / 2 + 0.5)
- Hitbox.CFrame = CFrame.new(HRP.Position + FrontOffset, HRP.Position + FrontOffset + HRP.CFrame.LookVector)
- end
- end
- end
- local Connection
- Connection = RunService.PostSimulation:Connect(function()
- if not Character or not Character:IsDescendantOf(Workspace) then
- Connection:Disconnect()
- else
- UpdateHitboxPosition()
- end
- end)
- return Hitbox
- end
- return HitboxModule
Advertisement
Add Comment
Please, Sign In to add comment