You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
it removes 70 then add 80 -
What is the issue? Include screenshots / videos if possible!
i get 150 -
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.