Number value is not going down

Hi, I have this system where if you take damage by a weapon, you lose an amount of blood. This might sound confusing but. Every time the value is added by amount of blood, I need it to go down. But its just going up by the amount of blood I set.

humanoid.HealthChanged:Connect(function(a)
	if tag.Value == itemTable.LongSword.itemKey then
		bloodLoss.Value += 8
	end
end)

local oldValue = bloodLoss.Value
bloodLoss:GetPropertyChangedSignal('Value'):Connect(function()
	for i = bloodLoss.Value,0,-1 do
		task.wait(1)
		bloodLoss.Value = i
	end
end)

it might be confusing but atleast try to help please

1 Like

You do realise that setting the bloodLoss value inside of that event will trigger that event, right?

And where does tag.Value come from in the HealthChanged event?

1 Like

Instead of making a for loop, just instead decrease the bloodLoss value by -1 by itself, and add a guard clause to prevent the bloodLoss value from continuously going down.

bloodLoss:GetPropertyChangedSignal('Value'):Connect(function()
	if bloodLoss.Value <= 0 then return end
	bloodLoss.Value -= 1
end)
1 Like

That would make their bloodLoss.Value infinitely low, would it not?

1 Like

Oh right, did not think of that…

I’ll edit my post.

1 Like

Instead of a for i loop, use while loops. This is more efficient and works well. It can be done by using boolean variables (to check and activate it) also make sure to use an elseif statement and use break after some time to end the loop.

1 Like

So are they supposed to gain more blood over time or less blood? I am a bit unclear on that. Why not just use a value called Blood instead and decrement it when hit by a weapon and check if the player is currently bleeding out or not. If they are not bleeding out, then make them bleed out.

And once again, where are you getting this tag variable from?

1 Like

Tag is what weapon was used to damage the player

1 Like

I don’t see how that will guarantee that it is the sword unless you connect this event before you damage them with the sword, rendering it pointless. Where is this variable defined?

1 Like

The player’s character. The tag is set by the tool itself, this is a different script

1 Like

Might sound confusing but let say i have a value that goes down by 1, and i have an amount of blood. If i add that amount of blood onto the value I still need it to go down by 1. @seancool07777

1 Like
local isBleeding = false

function startCountdown(a)
	for i = a,0,-1 do
		if isBleeding == true then
			task.wait(1)
			bloodInstance:EmitAmount(rootPart.Position,nil,a)
			print(i)
		elseif isBleeding == false or nil then
			return false
		end
	end
end
function stopCountdown()
	isBleeding = false
	
end
humanoid.HealthChanged:Connect(function(a)
	if tag.Value == itemTable.LongSword.itemKey then
		isBleeding = false
		startCountdown(6)
		
	end
end)

hey guys, i rewrote it kinda, im trying the update the countdown by adding the table value to the amount. but how?