Subtracting & checking attribute numbers

Hi, I am making a mining system where a rock’s health is set via attributes. How do I subtract from the attribute value and check if its <= 0?

Hitbox.Touched:Connect(function(Mined : BasePart)
	if Debounce and Mined:HasTag("Mineable") and not MiningEvent then
		MiningEvent = true
		HitSound:Play()
		
		Mined:SetAttribute("MineableHealth", Mined:GetAttribute("MineableHealth" - Damage))
		Mined.Size = Vector3.new(Mined.Size.X / 1.2, Mined.Size.Y / 1.2, Mined.Size.Y / 1.2)
		
		if Mined:GetAttribute("MineableHealth" <= 0) then
			Mined:Destroy()
		end
		
		task.wait(Cooldown)
		MiningEvent = false
	end
end)

Mined:SetAttribute("MineableHealth", Mined:GetAttribute("MineableHealth" - Damage))

You should have the Damage subtraction outside the GetAtrribute like this:

Mined:SetAttribute("MineableHealth", Mined:GetAttribute("MineableHealth") - Damage)

Do subtraction operation separately before setting the new attribute value, use a variable to check if the health is less than or equal to 0.

If you need me to edit the code lmk.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.