I am making some weapons, with chances of having bleeding in them. For this example i use the Basic Knife, which has the chance of 20% to bleed for 20 seconds, dealing 1 damage every second, making that a total 20 damage.
I was trying to make this, there are no errors in the script, but for some reason the script makes a 100% bleedchance, and the bleeding only deals a total of 1 damage.
This is my script:
-- Main variables local hitbox = script.Parent canDamage = true canEffect = true -- Configurations damage = 35 reload = 0.75 effectChance = 2 --/10 -- Attack hitbox.Touched:connect(function(hit) if (hit.Parent.ClassName == "Model") then if (hit.Parent:FindFirstChild("HumanoidEnemy")) then if canDamage == true then hit.Parent.HumanoidEnemy:TakeDamage(damage) print(hit.Parent.Name .. " took " .. damage .. " damage") local randomEffectChance = math.random(1, 10) print("The number of randomEffectChance = " .. randomEffectChance) if randomEffectChance == 1 or 2 then if canEffect == true and canDamage == true then canEffect = false print(hit.Parent.Name .. " got an effect") for i = 0, 20, 1 do hit.Parent.HumanoidEnemy:TakeDamage(1) print(hit.Parent.Name .. " is taking 1 damage") wait(1) end end end canDamage = false wait(reload) canDamage = true end end end end)
BTW, i made the enemy humanoid another name so you cant damage teammates. I called them "HumanoidEnemy", and there is another working script that makes the animations.
Thanks in advance
So the line if randomEffectChance == 1 or 2 then
should be if randomEffectChance == 1 or randomEffectChance == 2 then
They way you've got it at the moment is basically if ((randomEffectChance == 1) or (2)) then
Since 2
is a "truthy" value, it basically means that if 2 then
always fires, in the same way that if 1 then
always fires.
So what you have here is
((randomEffectChance == 1) or (2))
which evaluates to
((randomEffectChance == 1) or (true))
and since the right hand side of the or
is always true, the whole thing is always true, giving
if true then
explaining why it always fires.