I made a bat that uses a hitbox module. The hitbox module is very known and i’m not sure if I set it up correctly. The localscript is very small hopefully you can read it
local Tool = script.Parent
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
Handle = Tool:WaitForChild("Handle")
local Hitbox = RaycastHitbox.new(Handle)
-- Player
local Player = game.Players.localPlayer
local Debris = game:GetService("Debris")
-- Folders
local animFolder = script.Parent.Animations
local eventFolder = script.Parent.Events
local soundFolder = script.Parent.Sounds
-- Animations
local equipAnim = animFolder.Equip
local idleAnim = animFolder.Idle
local swingAnim = animFolder.Swing1
local swingAnim2 = animFolder.Swing2
-- Sounds
local equipSound = soundFolder.Equip
local swingSound = soundFolder.Swing1
local swingSound2 = soundFolder.Swing2
-- Events
local swingEvent = eventFolder.Swing
-- Scripts
--
local debounce = false
local actDebounce = false
local combo = 1
CanHit = true
-- Values
local Damage = Tool.Settings.Damage
local function ToolEquipped()
if not debounce then
debounce = true
local humanoid = script.Parent.Parent.Humanoid
equip = humanoid:LoadAnimation(equipAnim)
idle = humanoid:LoadAnimation(idleAnim)
Hitbox.DetectionMode = RaycastHitbox.DetectionMode.PartMode
Hitbox.Visualizer = true
equip:Play()
equipSound:Play()
wait()
idle.Looped = true
idle:Play()
debounce = false
end
end
local function Unequipped()
if equip.IsPlaying then
equip:Stop()
end
if idle.IsPlaying then
idle:Stop()
end
end
local function Activated()
if not debounce then
debounce = true
if combo == 1 then
local swing = Tool.Parent.Humanoid:LoadAnimation(swingAnim)
CanHit = true
Hitbox:HitStart()
swing:Play()
swingSound:Play()
wait(1)
combo = 2
Hitbox:HitStop()
CanHit = false
wait(0.3)
debounce = false
elseif combo == 2 then
local swing2 = Tool.Parent.Humanoid:LoadAnimation(swingAnim2)
swing2:Play()
swingSound2:Play()
CanHit = true
Hitbox:HitStart()
swingEvent:FireServer()
wait(1)
Hitbox:HitStop()
CanHit = false
wait(0.3)
combo = 1
debounce = false
end
end
end
Hitbox.OnHit:Connect(function(hit, humanoid)
if humanoid and humanoid ~= script.Parent.Parent.Humanoid then
local dmg = 20
humanoid:TakeDamage(dmg)
end
end)
Tool.Equipped:Connect(ToolEquipped)
Tool.Unequipped:Connect(Unequipped)
Tool.Activated:Connect(Activated)