Can't make the table names be required for a function and more issues

Edit: There’s a general idea going on in the script now, it deletes all ingredients upon clicking and makes the potion, however there are a few problems- it only goes through if you have at least one ingredient on the table, when I need it to require all three in the player’s backpack not one by one to make the potion, third it won’t let me make more than one potion. Is it really that impossible to do this? I’ve been at this for 5 hours trying to figure it out…

Now this happens after working on it more, please any help is appreciated

local ClickDetector = script.Parent.ClickDetector
local RS = game:GetService("ReplicatedStorage")
local Vial1 = game:GetService("ReplicatedStorage").Potion

local toolName = {
	"Ingredient1",
	"Ingredient2",
	"Ingredient3",
}

local used = false

function onClicked(Player)
	if used == false then
		for i,v in pairs(Player.Backpack:GetChildren()) do
			for index, name in pairs(toolName) do
				if v.Name == name then
					v:Destroy()
				end
			end
			if Player.Backpack:FindFirstChild(Vial1.Name) == nil and Player.Character:FindFirstChild(Vial1.Name) == nil then
				local Potion = Vial1:Clone()
				Potion.Parent = Player.Backpack
				used = false
			else
				print("lol")
			end
		end
	end
end

ClickDetector.MouseClick:Connect(onClicked)```

Maybe this might work:

(Note that I have slightly reworked the way that it checks for completition and ensures you have the potions)

local ClickDetector = script.Parent.ClickDetector
local RS = game:GetService("ReplicatedStorage")
local Vial1 = game:GetService("ReplicatedStorage").Potion

local toolName = {
	"Ingredient1",
	"Ingredient2",
	"Ingredient3",
}

local inCauldron = {}

for _, value in ipairs(toolName) do
    inCauldron[value] = false; --Just so you only have to modify the ingredients once
                               -- I have used a loop to do it auto-magically
end


local function MouseClick(Player)
    local completed = true

    for _, value in pairs(toolName) do
        if not inCauldron[value] do
            
            if Player.Backpack:FindFirstChild(value) then
                 inCauldron[value] = true
                 Player.Backpack:FindFirstChild(value):Destroy()

            elseif Player.Character:FindFirstChild(value) then
                 inCauldron[value] = true
                 Player.Character:FindFirstChild(value):Destroy()
            else
                completed = false
            end 

        end        


    end	
	if Player.Backpack:FindFirstChild(Vial1.Name) == nil and Player.Character:FindFirstChild(Vial1.Name) == nil then
		local Potion = Vial1:Clone()
		Potion.Parent = Player.Backpack
		
		for _, value in pairs(inCauldron) do
		    value = false
		end
		
	end
end

ClickDetector.MouseClick:Connect(MouseClick)

The modifications I made mean that any player can put an ingredient in, then once all the ingredients are put in then the potion can be taken out ONE TIME.

1 Like

I appreciate the help, though the point of the cauldron was that it was station that you could craft the potion any amount of times, maybe it’s just impossible to do it where you can craft it as many times as you want.

I’ll just try and learn from your code set up and see if I can get it working

The code I provided requires that the ingredients are all present to craft it each time. When I said it allows the potion to be taken out one time, I meant that you would have to re-add the ingredients

1 Like

With your code I get an error at line 23, if I change it to then it does craft the potion once, but if you have the ingredients in your inventory once more it won’t let you craft the potion again

potion test debugging.rbxl (45.1 KB)

your modified code;

local ClickDetector = script.Parent.ClickDetector
local RS = game:GetService("ReplicatedStorage")
local Vial1 = game:GetService("ReplicatedStorage").Potion

local toolName = {
	"Ingredient1",
	"Ingredient2",
	"Ingredient3",
}

local inCauldron = {}

for _, value in ipairs(toolName) do
	inCauldron[value] = false; --Just so you only have to modify the ingredients once
	-- I have used a loop to do it auto-magically
end


local function MouseClick(Player)
	local completed = true

	for _, value in pairs(toolName) do
		if not inCauldron[value] do -- expected 'then' when parsing, got do
				-- if its changed to then then it does what it does but won't let you craft it again with ingredients in your inventory

				if Player.Backpack:FindFirstChild(value) then
					inCauldron[value] = true
					Player.Backpack:FindFirstChild(value):Destroy()

				elseif Player.Character:FindFirstChild(value) then
					inCauldron[value] = true
					Player.Character:FindFirstChild(value):Destroy()
				else
					completed = false
				end 

			end        


	end	
	if Player.Backpack:FindFirstChild(Vial1.Name) == nil and Player.Character:FindFirstChild(Vial1.Name) == nil then
		local Potion = Vial1:Clone()
		Potion.Parent = Player.Backpack

		for _, value in pairs(inCauldron) do
			value = false
		end

	end
end

ClickDetector.MouseClick:Connect(MouseClick)

edited below

local ClickDetector = script.Parent.ClickDetector
local RS = game:GetService("ReplicatedStorage")
local Vial1 = game:GetService("ReplicatedStorage").Potion

local toolName = {
	"Ingredient1",
	"Ingredient2",
	"Ingredient3",
}

local inCauldron = {}

for _, value in ipairs(toolName) do
	inCauldron[value] = false; --Just so you only have to modify the ingredients once
	-- I have used a loop to do it auto-magically
end


local function MouseClick(Player)
	local completed = true

	for _, value in pairs(toolName) do
		if not inCauldron[value] then -- expected 'then' when parsing, got do
				-- if its changed to then then it does what it does but won't let you craft it again with ingredients in your inventory

				if Player.Backpack:FindFirstChild(value) then
					inCauldron[value] = true
					Player.Backpack:FindFirstChild(value):Destroy()

				elseif Player.Character:FindFirstChild(value) then
					inCauldron[value] = true
					Player.Character:FindFirstChild(value):Destroy()
				else
					completed = false
			end
		end
		if Player.Backpack:FindFirstChild(Vial1.Name) == nil and Player.Character:FindFirstChild(Vial1.Name) == nil then
			local Potion = Vial1:Clone()
			Potion.Parent = Player.Backpack
			for _, value in pairs(inCauldron) do
				value = false
			end

		end
	end
end

ClickDetector.MouseClick:Connect(MouseClick)

I tried something new, now it changes all three of the ingredients into what should be just one tool, need help


local toolName = {
	"Ingredient1",
	"Ingredient2",
	"Ingredient3",
}

local q = "Potion"

local Used = false

function onClicked(Player)
	for i,v in pairs(Player.Backpack:GetChildren()) do
		for index, name in pairs(toolName) do
			if v.Name == name then
				v:Destroy()
				local z = game.ReplicatedStorage:FindFirstChild(q)
				z:Clone().Parent = Player.Backpack
				Used = false
			else
				print("u tried")
			end
		end
	end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)```

I think I’m gonna go to bed, this is really hard to figure out :confused: I thought I understood it well enough