Advertisement
XXsuperninjaXXop

weapons code

Jun 8th, 2025
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | Source Code | 0 0
  1. local module = {}
  2.  
  3. -- Cache frequently accessed objects
  4. local Debris = game:GetService("Debris")
  5. local slashEffects = game.ReplicatedStorage.SlashEffects:GetChildren()
  6. local numSlashEffects = #slashEffects
  7.  
  8. function module.DamageHandler(tool:Tool|BasePart, hit:BasePart, knockback:number?,DoSlashes:boolean?,CritBoost:number?)
  9.     local hitParent = hit.Parent
  10.     local toolParent = tool.Parent
  11.     if not hitParent or not toolParent then return end
  12.     local hitHumanoid = hitParent:FindFirstChild("Humanoid")
  13.     local toolHumanoid = toolParent:FindFirstChild("Humanoid")
  14.     local hitTeam = hitParent:FindFirstChild("Team")
  15.     local toolTeam = toolParent:FindFirstChild("Team")
  16.    
  17.     if not (hitHumanoid and toolHumanoid and hitTeam and toolTeam) then return end
  18.    
  19.     -- 0 is npcs 1 is players 3 is pvp players
  20.     if (toolTeam.Value == 3 and hitTeam.Value == 1) or (toolTeam.Value == 1 and hitTeam.Value == 3) then
  21.         return
  22.     end
  23.  
  24.     if hitParent == toolParent or (toolTeam.Value ~= 3 and toolTeam.Value == hitTeam.Value) then
  25.         return
  26.     end
  27.    
  28.     local dmg = tool.Damage
  29.     if not dmg then return end
  30.  
  31.     if CritBoost and CritBoost > 1 and tool:FindFirstChild("CritSlash") then
  32.         tool.CritSlash:Play()
  33.     elseif tool:FindFirstChild("Slash") then
  34.         tool.Slash:Play()
  35.         CritBoost = 1
  36.     else
  37.         CritBoost = 1
  38.     end
  39.    
  40.    
  41.     local char = toolParent
  42.     local hitRootPart = hitParent:FindFirstChild("HumanoidRootPart")
  43.     if not hitRootPart then return end
  44.    
  45.     local player = game.Players:GetPlayerFromCharacter(toolParent)
  46.     if player then
  47.         local tag = Instance.new("ObjectValue")
  48.         tag.Value = player
  49.         tag.Name = "creator"
  50.         tag.Parent = hitHumanoid
  51.         game:GetService("Debris"):AddItem(tag, 0.5)
  52.     end
  53.    
  54.     local shield = hitParent:FindFirstChild("Shield")
  55.     if shield and shield:FindFirstChild("Health") then
  56.         local angle = math.acos(hitRootPart.CFrame.LookVector:Dot((toolParent.HumanoidRootPart.Position - hitRootPart.Position).Unit))
  57.         if angle < math.pi/2 then
  58.             shield.Health.Value = math.max(0, shield.Health.Value - (dmg.Value * CritBoost))
  59.             return
  60.         end
  61.     end
  62.    
  63.     if DoSlashes and hitRootPart:FindFirstChild("SlashesGUI") then
  64.         local randomSlash = slashEffects[math.random(1, numSlashEffects)]:Clone()
  65.         if CritBoost > 1 then
  66.             randomSlash.ImageColor3 = Color3.fromRGB(255, 0, 0)
  67.             randomSlash.ImageTransparency = 0
  68.         end
  69.         randomSlash.Parent = hitRootPart.SlashesGUI
  70.     end
  71.  
  72.     local healthValue = hitHumanoid:FindFirstChild("Health")
  73.     if healthValue and healthValue:IsA("NumberValue") then
  74.         hitHumanoid.Health.Value -= dmg.Value * CritBoost
  75.     else
  76.         hitHumanoid.Health -= dmg.Value * CritBoost
  77.     end
  78.    
  79.     if knockback then
  80.         hitRootPart.AssemblyLinearVelocity = (hitRootPart.Position - toolParent.HumanoidRootPart.Position).Unit * knockback
  81.     end
  82. end
  83.  
  84. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement