Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with getting a value from a table to a client?

I'm making a crafting script. I've gotten to the point where I'm nearly done, but I need to tell the player how much ingredients they need to craft something. I have a table of recipes (shown here),

local CraftingRecp = {
	["Resource"] = {5, 15, "ToolName", "Resource1Name", "Resource2Name"},
	
	["Stone Hatchet"] = {5, 5, "Stone Hatchet", "Sticks", "Stones"},
	["Stone Pickaxe"] = {3, 7, "Stone Pickaxe", "Sticks", "Stones"},
}
--there are more recipes, i just cut some off.

and I somehow wanna get (on the client) some of the info such as the Ingredient Name and Ingredient Value.

For example, Person types in "Stone Hatchet" and presses on a GUI button that reads "View Recipe". Then the local script gets the recipe's ingredients and amounts and changes the text of some buttons in the gui to that value. (FilteringEnabled is on and i'm using RemoteFunctions to craft already.)

How would I do that?

In my mind it would be something like

script.Parent.MouseButton1Click:connect(function()
	game.ReplicatedStorage.GetRecipeInfo:InvokeServer("Stone Hatchet")
end)

Can someone help me out? Thanks!

2 comments

0

if the links say not found, remove the , from the end of the url

1 answer

✓ Accepted answer

Heres your code:

local CraftingRecp = {
 ["Resource"] = {5, 15, "ToolName", "Resource1Name", "Resource2Name"}}

So, if we want to reference the first resource needed there, we would do:

CraftingRecp.Resource[4]

Because resource is a string, we can just go straight to that, or use the ["THING NAME"] format, because Resource1 is the 4th variable in the table, we have to call it by saying [4] rather than .4 . So, as long as you're using that format for every weapon, all you'll need is:

CraftingRecp.["Stone Hatchet"][4]
CraftingRecp.["Stone Hatchet"][5]

Hope it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.