Here is the DamageModule
:
--< SERVICES >--
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local plrs = game:GetService("Players")
local debris = game:GetService("Debris")
------------------------------------------------------------------------------------------------------------
--< VARIABLES >--
local damageIndicatorInfos = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
local abbreviations = {"", "K", "M", "B", "T" , "Qd", "Qn", "Sx", "Sp", "Oc", "No", "Dc", "Un", "Duo", "Tre", "Qua", "Qui", "Sed", "Sep", "Oct", "Nov", "V"}
local damageModule = {}
------------------------------------------------------------------------------------------------------------
--< FUNCTIONS >--
local function Format(value, idp)
local ex = math.floor(math.log(math.max(1, math.abs(value)),1000))
local abbrevs = abbreviations[1 + ex] or ("e+"..ex)
local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)
return ("%."..idp.."f%s"):format(normal, abbrevs)
end
------------------------------------------------------------------------------------------------------------
--< MODULE FUNCTION >--
damageModule.Damage = function(hit, tool, damage, bloodDuration)
local alreadyHit = {}
local damageIndicator = rs:WaitForChild("DamageBillboard"):Clone()
local hitSound = script:WaitForChild("HitSound"):Clone()
local enemyCharacter = hit.Parent
local enemyHumanoid = enemyCharacter:FindFirstChildOfClass("Humanoid")
local isMob = enemyCharacter:FindFirstChild("IsMob")
local isBlocking = enemyCharacter:FindFirstChild("IsBlocking")
local damageDealer = plrs:GetPlayerFromCharacter(tool.Parent)
local function TagHumanoid()
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = damageDealer
game.Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = enemyHumanoid
end
local function SoulEffect()
local soulEffectBeam = rs:WaitForChild("SoulEffect"):Clone()
soulEffectBeam.Parent = workspace
local attachment0 = Instance.new("Attachment", enemyCharacter:WaitForChild("Head"))
local attachment1 = Instance.new("Attachment", tool:WaitForChild("Handle"):FindFirstChild("Sword"))
soulEffectBeam.Attachment0 = attachment0
soulEffectBeam.Attachment1 = attachment1
wait(2.5)
soulEffectBeam:Destroy()
end
if enemyCharacter.Name == damageDealer.Character.Name then return end
if hit and hit.Parent:FindFirstChild("Humanoid") then
if isMob then
if isBlocking.Value == false then
if table.find(alreadyHit, hit.Parent) then return
else
local blood = rs:WaitForChild("Blood"):WaitForChild("Attachment"):Clone()
blood.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
hitSound.Parent = hit.Parent
damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage, 0))
ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
debris:AddItem(blood, bloodDuration)
debris:AddItem(hitSound, 3)
debris:AddItem(damageIndicator, 3)
hitSound:Play()
TagHumanoid()
enemyHumanoid.Died:Connect(SoulEffect)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
table.insert(alreadyHit, hit.Parent)
end
end
if isBlocking.Value == true then
if table.find(alreadyHit, hit.Parent) then return
else
hitSound.Parent = hit.Parent
damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage / 2, 0))
damageIndicator:WaitForChild("TextLabel").TextColor3 = Color3.fromRGB(83, 201, 255)
ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
debris:AddItem(hitSound, 3)
debris:AddItem(damageIndicator, 3)
hitSound:Play()
TagHumanoid()
enemyHumanoid.Died:Connect(SoulEffect)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage / 2)
table.insert(alreadyHit, hit.Parent)
end
end
else
if isBlocking.Value == false then
if table.find(alreadyHit, hit.Parent) then return
else
local blood = rs:WaitForChild("Blood"):WaitForChild("Attachment"):Clone()
blood.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
hitSound.Parent = hit.Parent
damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage, 0))
ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
debris:AddItem(blood, bloodDuration)
debris:AddItem(hitSound, 3)
debris:AddItem(damageIndicator, 3)
hitSound:Play()
TagHumanoid()
enemyHumanoid.Died:Connect(SoulEffect)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
table.insert(alreadyHit, hit.Parent)
end
end
if isBlocking.Value == true then
if table.find(alreadyHit, hit.Parent) then return
else
hitSound.Parent = hit.Parent
damageIndicator.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
damageIndicator:WaitForChild("TextLabel").Text = "-"..tostring(Format(damage / 2, 0))
damageIndicator:WaitForChild("TextLabel").TextColor3 = Color3.fromRGB(83, 201, 255)
ts:Create(damageIndicator, damageIndicatorInfos, {SizeOffset = Vector2.new(0,1)}):Play()
debris:AddItem(hitSound, 3)
debris:AddItem(damageIndicator, 3)
hitSound:Play()
TagHumanoid()
enemyHumanoid.Died:Connect(SoulEffect)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage / 2)
table.insert(alreadyHit, hit.Parent)
end
end
end
end
end
------------------------------------------------------------------------------------------------------------
--< RETURNING MODULE >--
return damageModule
And if you’re wondering what the hit
paramenter is, basically (from the server script) i’m calling the module script when they touch a part.