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!
get the actually #table printed -
What is the issue? Include screenshots / videos if possible!
it prints 0 -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
adding more to the table
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 = 1
wood.Name = 'wood'
wood.Changed:Connect(print)
local recipeResult=mm.new('Instant',{In = {wood = 50,stone=70},Out={Value=80,Name='wood'},Name='Qin2007sFirst'})
print(recipeResult:Craft(game.Players:WaitForChild('Qin2007')))
--module script
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
--print(k,v)
local ingredient = player:WaitForChild(k,7)
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
else
return false,'cant find'
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
else
print(self.ingredients,#self.ingredients,typeof(self.ingredients))
end
error('whaaaaaaaa')
end
return recipeResult
end
return module
mainModuleScript
--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.
about the same as the scripts in this topic