Currently, it only dmgs players, but when I use don npcs it returns an error, I understand that it’s due to the leaderstats,but how would I make a work around it?
local module = {}
module.Hitbox = function(Character:Model, CFrameOffset:CFrame, Size:number, Damage:number, BlockDamage:number, VfxPart:BasePart)
local Hrp = Character:FindFirstChildOfClass("Humanoid").RootPart
local player = game.Players:GetPlayerFromCharacter(Character)
local rs = game:GetService("ReplicatedStorage")
local Hitbox = workspace:GetPartBoundsInBox(Hrp.CFrame * CFrameOffset, Vector3.one * Size)
local Filtered = {}
for _, Parts in Hitbox do
local PossibleCharacter = Parts.Parent
if PossibleCharacter == Character or table.find(Filtered, PossibleCharacter) or not PossibleCharacter:IsA("Model") then continue end
local Humanoid = PossibleCharacter:FindFirstChildOfClass("Humanoid")
if not Humanoid then continue end
local VfxClone = VfxPart:Clone()
local ParryVfx = rs.ParryVfx:Clone()
local PossiblePlayer = game.Players:GetPlayerFromCharacter(PossibleCharacter)
local leaderstats = PossiblePlayer:WaitForChild("leaderstats")
local BlockValue = leaderstats.BlockValue
if PossibleCharacter:GetAttribute("IsBlocking") == true and PossibleCharacter:GetAttribute("Parrying") == false and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
BlockValue.Value -= BlockDamage
end
if PossibleCharacter:GetAttribute("IsBlocking") == false and PossibleCharacter:GetAttribute("Parrying") == false and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
Humanoid:TakeDamage(Damage)
VfxClone.CFrame = Humanoid.RootPart.CFrame
VfxClone.Parent = workspace
PossibleCharacter:SetAttribute("Stunned", true)
task.wait(1)
PossibleCharacter:SetAttribute("Stunned", false)
end
if PossibleCharacter:GetAttribute("IsBlocking") == true and PossibleCharacter:GetAttribute("Parrying") == true and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
--local katanaParry = game:GetService("ReplicatedFirst").Animations.KatanaParry
--local KatanaParryTrack = hum:LoadAnimation(katanaParry)
--KatanaParryTrack:Play()
ParryVfx.Parent = workspace
ParryVfx.CFrame = PossibleCharacter:WaitForChild("Humanoid").RootPart.CFrame
end
game.Debris:AddItem(ParryVfx,0.5 )
table.insert(Filtered, PossibleCharacter)
task.delay(0.5, game.Destroy, VfxClone, ParryVfx)
end
table.clear(Filtered)
end
return module