Guest User

bleeding

a guest
Jul 7th, 2018
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. -- Main variables
  2.  
  3. local hitbox = script.Parent
  4. canDamage = true
  5. canEffect = true
  6.  
  7. -- Configurations
  8.  
  9. damage = 5
  10. reload = 0.75
  11. effectChance = 2 --/10
  12.  
  13. -- Attack
  14.  
  15. hitbox.Touched:connect(function(hit)
  16.     if (hit.Parent.ClassName == "Model") then
  17.         if (hit.Parent:FindFirstChild("Humanoid")) then
  18.             if canDamage then -- `canDamage == true` is the same thing as `canDamage`
  19.                 hit.Parent.Humanoid:TakeDamage(damage)
  20.                 print(hit.Parent.Name .. " took " .. damage .. " damage")
  21.  
  22.                 local randomEffectChance = math.random(1, 10)
  23.                 print("The number of randomEffectChance = " .. randomEffectChance)
  24.                 if randomEffectChance <= effectChance then -- slightly more concice way
  25.                     if canEffect then -- We don't need to check `canDamage` here, because we already checked it above
  26.                         canEffect = false
  27.                         print(hit.Parent.Name .. " got an effect")
  28.                         for i = 1, 20, 1 do
  29.                             hit.Parent.Humanoid:TakeDamage(1)
  30.                             print(hit.Parent.Name .. " is taking 1 damage")
  31.                             wait(1)
  32.                         end
  33.                         canEffect = true -- We never actually reset this before
  34.                     end
  35.                 end
  36.  
  37.                 canDamage = false
  38.                 wait(reload)
  39.                 canDamage = true
  40.             end
  41.         end
  42.     end
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment