I went ahead and rewrote the entire script, hopefully it should work now:
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local modules = ServerScriptService.Modules
local attackmod = require(modules.Attack)
local Power = script.Power
local attackData = {
Damage = 0 + Power.Value,
StartUp = 0.2,
Knockback = Vector2.new(40 + Power.Value, 20),
Stun = 2,
Linger = 0.4,
Sound = "Bonk"
}
local playerHit = ServerStorage.PlayerHit
local tool = script.Parent
local attackAnim
local character
local toolDebounce = false
local hitboxDebounce = false
local function onActivated()
if toolDebounce then return end
toolDebounce = true
attackAnim:Play()
attackmod.Start(character, tool, attackData)
task.wait(1)
toolDebounce = false
end
local function onPowerChanged(value)
attackData = {
Damage = 0 + value,
StartUp = 0.2,
Knockback = Vector2.new(40 + value, 20),
Stun = 2,
Linger = 0.4,
Sound = "Bonk"
}
end
local function onTouched(hit)
if hitboxDebounce then return end
local model = hit:FindFirstAncestorOfClass("Model")
if model and model ~= character and not model:FindFirstChild("PlayerHit") then
local humanoid = model:FindFirstChildWhichIsA("Humanoid")
if humanoid then
hitboxDebounce = true
local playerHitClone = playerHit:Clone()
playerHitClone.Value = character.Name
playerHitClone.Parent = model
task.wait(1)
hitboxDebounce = false
end
end
end
tool.Equipped:Once(function()
character = tool.Parent
attackAnim = character.Humanoid.Animator:LoadAnimation(script.Attack)
end)
tool.Activated:Connect(onActivated)
Power.Changed:Connect(onPowerChanged)
tool.Hitbox.Touched:Connect(onTouched)
If it still doesn’t work then the issue might be that the hitbox keeps colliding with the tool’s handle, which you’ll need to separate into different collision groups in-order to solve