Sum should be 70-70+80 not 70+80

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    it removes 70 then add 80
  2. What is the issue? Include screenshots / videos if possible!
    i get 150
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    returning when it is below 0
    other values

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--script
local mm = require(script.Parent.MainModule)
local wood = Instance.new("NumberValue",game.Players:WaitForChild('Qin2007'))
wood.Value = 70
wood.Name = 'wood'
wood.Changed:Connect(print)
local recipeResult=mm.new('Instant',{In = {wood = 70},Out={Value=80,Name='wood'},Name='Qin2007sFirst'})
print(recipeResult:Craft(game.Players:WaitForChild('Qin2007')))
--modulescript
local module = {}
function module.getRecipe(recipe)
	local recipeResult = {ingredients={recipe.In}}
	recipeResult.Out = recipe.Out
	recipeResult['Name'] = recipe.Name
	--
	
	function recipeResult:Craft(player)
		if #self.ingredients>0 then
			local payd = true
			for k,v in pairs(self.ingredients) do
				local ingredient = player:FindFirstChild(k)
				if ingredient then
					ingredient.Value -= v.Value
					if ingredient.Value < 0 then
						ingredient += v.Value
						print('he cant pay')
						return false, 'he cant pay'
						
					end
				end
				
			end
			local out = player:FindFirstChild(self.Out.Name)
			if out then
				out.Value += self.Out.Value
				return true, Enum.ProductPurchaseDecision.PurchaseGranted
			else
				--refund
				for k,v in pairs(self.ingredients) do
					local ingredient = player:FindFirstChild(k)
					ingredient += v.Value
				end
				return false,Enum.ProductPurchaseDecision.NotProcessedYet
			end
		end
	end
	return recipeResult
end

return module

other module script
--mainModuleScript
local module = {}
RunService=game:GetService("RunService")
function getfolder(Name)
	local name = 'Qin2007s crafting recipe_'..Name
	local folder = game.ReplicatedStorage:FindFirstChild(name)
	if not folder then
		folder = Instance.new("Folder")
		folder.Name = name
		folder.Parent = game.ReplicatedStorage
	end
	return folder
end
function module.new(CraftType,recipe)
	if recipe and recipe.In and recipe.Out and recipe.Name and RunService:IsServer() then
		--local folder = getfolder(recipe.Name)
		if CraftType == 'Chance' then
			return require(script.Chance).getRecipe(recipe)
		elseif CraftType == 'Instant' then
			return require(script.Instant).getRecipe(recipe)
		end
	else
		error('recipe.In or recipe.Out are not in the areguments or this is called on the client')
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Try 70+10 instead (if you don’t wanna do that )
If you’re forcing it to be 80, do

val = 80

Wouldn’t that mean that you should just set the value to 80?

if ingredient then
	ingredient.Value -= v.Value
	if ingredient.Value < 0 then
		ingredient += v.Value

I wouldn’t recommend doing transactions like this. Instead do it like this.

if ingredient then
	if ingredient.Value - v.Value < 0 then
		--reject payment
1 Like

You could simplify this further to:

if ingredient then
    if ingredient.Value > v.Value then
        -- reject payment

Edit: See reply.

if out then
				out.Value += self.Out.Value
				return true, Enum.ProductPurchaseDecision.PurchaseGranted
			else
				--refund
				for k,v in pairs(self.ingredients) do
					local ingredient = player:FindFirstChild(k)
					ingredient += v.Value
				end

Shouldn’t ingredient be ingredient.Value? Otherwise how are you increasing it by some value?

ingredient.Value += v.Value

Except that’s the wrong way round.

if ingredient then
	if ingredient.Value < v.Value then
		-- reject payment
1 Like

(post deleted by author)

1 Like

Addition and subtraction are on the same level. It goes P E MD AS

2 Likes

As it was said, in math addition and subtraction are done together left to right. This is because no matter the order of addition and subtraction, the result is the same.
1+2-3 = 1-3+2

In programming however we need to worry about a lot more than pemdas. Here’s the operator precedence for Lua. Anything on the same line is calculated left to right, and anything on a different line is done after the lines above it.

()
^
not  - (unary)
*   /
+   -
..
<   >   <=  >=  ~=  ==
and
or
1 Like

Are you familiar with the debugger? This is the perfect time to use it, I suggest you go read or watch a tutorial on the Roblox debugger and use it to find the flow of your code and see where the variables are changing.