Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Main variables
- local hitbox = script.Parent
- canDamage = true
- canEffect = true
- -- Configurations
- damage = 5
- reload = 0.75
- effectChance = 2 --/10
- -- Attack
- hitbox.Touched:connect(function(hit)
- if (hit.Parent.ClassName == "Model") then
- if (hit.Parent:FindFirstChild("Humanoid")) then
- if canDamage then -- `canDamage == true` is the same thing as `canDamage`
- hit.Parent.Humanoid:TakeDamage(damage)
- print(hit.Parent.Name .. " took " .. damage .. " damage")
- local randomEffectChance = math.random(1, 10)
- print("The number of randomEffectChance = " .. randomEffectChance)
- if randomEffectChance <= effectChance then -- slightly more concice way
- if canEffect then -- We don't need to check `canDamage` here, because we already checked it above
- canEffect = false
- print(hit.Parent.Name .. " got an effect")
- for i = 1, 20, 1 do
- hit.Parent.Humanoid:TakeDamage(1)
- print(hit.Parent.Name .. " is taking 1 damage")
- wait(1)
- end
- canEffect = true -- We never actually reset this before
- end
- end
- canDamage = false
- wait(reload)
- canDamage = true
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment