I am trying to get the names from items for a little ordering project, but there could be different amounts of items and I don't know how to get the names of them if there are different amounts each time. If this is confusing sorry, just ask me to elaborate or try to help explain more lmao.
#Getting item names from varying amount of items
1 messages · Page 1 of 1 (latest)
each time you add a new item you should have a table that keeps track of it with the item name as key and its count and then maybe reference that table
like what do you have right now that keeps track of what items are in the cart because if you dont have that then there is no way you can get the item names
okay, I kinda get what you're saying
but how would I add and removes items from a table?
Isn't a table written code?
table.insert() and table.remove() are methods that you can use to add and remove elements from a table
OH?
i suggest you look at the documentation to learn more about tables as they are pretty much the only data structure in roblox
and are essential
ahh alright, thanks! this was supposed to be an easy project, guess not 💀 😭
okay so, this is the script I put in each item to get added to the cart, @coarse minnow. is there a way to access a table that's in a seperate script? just like if I wanted to put a table.insert() in this script but have the table be in another? Because I don't think I can make it work if I have the table here. Sorry if this is confusing
can you still use the table.insert() and what not with those?
yes
as long as it returns a table
this is the format for modulescripts
local module = {}
return module
sweet, thanks. I'll just look into module scripts a little bit to figure out how to use em
and to get them you do this
local module = require(PathToModuleScript)
in the local script?
thanks!
where should I put the module script, in reference to the workspace?
** You are now Level 5! **
replicatedstorage
could I just put it in one of the ui elements or no?
i guess but it might be hard to find it
okie dokie, thanks!
like if you just put it in replicated storage its easier
kk
you just need to do require(game:GetService("ReplicatedStorage").ModuleName)
you have to getservice replicated storage?
BAHAH HWHAT?
I just do game.replicatedstorage.xxxx
or is it cus it's a module script
no it shouldnt make a difference
oh, alright!
i mean im looking right now but what get service does is this:
I'll take a look. Cus the only thing I ever had to do getservice for is tweening and what not
OHHH okay, that makes sense
you can use the instance tree to build the table, like loop through all of Menu.Background.Order.Cart :Children and insert Item.Text for the name, or give each item an attribute if the item's key name is different to its display name, and with this table you can fire it to your remote event. very simple really. there's always more than 1 way to solve any given problem 
so yes you can access the "table" of instances and get information that way, as opposed to messing around with a random empty modulescript
yea that would be better mb
I don't get it 😭
but you would have to parent those items added to the cart to that cart instance so get children actually gets the items in the cart
I should maybe research and learn a little more lmao
game:getservice is preferred method for all roblox services, it's mostly for preference and consistency, but for example if you rename ReplicatedStorage (yes you can rename them), then game.ReplicatedStorage won't work, but game:GetService("ReplicatedStorage") will.
a bit like you can do local Players=game.Players but it is my preference to call this local PlayerService=game:GetService("Players") so the 'Players' keyword isn't consumed by the service
no functional difference really, just preference.
@coarse minnow what'd i do wrong?
what didn't you do wrong in there...
LMFAO
no dont use what i did @timid citrus 's suggestion was better
scold me all I want
but I don't get the suggestion and lowk don't want to
just parent the items added to the cart to the cart ui
then get those items by doing the get children method on the cart ui
you're already creating ui instances with the information you want. you can also read this information back from the instances with like getchildren
But, the whole idea is to get that information and put it into a server wide ui thingy
so not on the client side
yeah get the information on the client then send it to the server ?
well on the client side, just for everyone
so like when you add snickers to the cart, is there a new text label being created with the text snickers that is being parented to the cart ui?
then use get children from the cart ui to get back the names of each food item
right now its 'Item#'..cartAmount.value
and then still use the table?
no because get children returns a table
ohh okay
of all the children
luau is all about working with tables
so even if the amount of items is changing, it's still going to get all of them?
yeah probably, lowk underestimated how much knowledge I needed for this project
yes because if you add 3 snickers then there should be 3 text labels with the snickers text under the cart gui
debatable. im jk
in fact you dont even really need to use an int value to keep track of how many items are in the cart
you could just get the length of the table returned by get children
Thanks, but I'm NOT re doing the entire thing I've got so far 😭
you say that like 90% of code doesn't get thrown out
you can use this operator to get the length: #
because that's true - it's closer to 95% which gets thrown out 
where do you parent the items
the cart
when you add them to the cart
Ill show you
well, it's printing all the data, and the cartItems are in the data
so the items go inside the cart
if any of this is confusing lmk
idk why get children is returning an empty table
that would mean it has no children
maybe you can invite me to team create and i can see
looks good on that side, add a print there to see the contents of cartItems
hes printing on the server but its an empty table
oh i see yea they're passing the instances directly which only exist on client
need to pass the names
ohh
getchildren gets you the instances, you need to do the next step and build a table of all the names from those instances
which is just a trivial for loop
cant you also access the player's cart ui through player gui on the server?
nope
not through the server
you can if you created it on the server, but that is not the case here
yea that would be better
alr
wait no
I can't do that
cus then it takes away all of the other stuff
wait no
not that
it takes away the ui list layout
then create a separate frame with only the ui list layout and the food items
hmm okie dokie
or I could just put it in a folder with the layout
that's what I did
if thing:IsA("Frame")
so how would one do this
okay so wait
I think maybe
I do get children
and then I do something like if it is a frame then put it on a table yeah?
if I can spell 💀
so filter the stuff in the table for what you want, most likely is frames
okay, but I can't do something like this
so what should I do instead
OHH
should it be in an if statement or smth?
dont do that
I know
just do cart:getchildren
it won't work
then when you iterate through it
kk
check if its a frame
like this:
local itemNames = {}
for i, v in cartItems do
if v:IsA("Frame") then
table.insert(itemNames, v.Name)
end
end
kk
** You are now Level 6! **
do this assuming that each of the frames are named the item
like just modify it to get the name
in the mouse button 1 click event
ahh okay okay
so what it does is it goes through the cartItems table, where v is the child of the cart ui, and then it checks whether or not v is a frame, if it is then it appends (adds to the end of the table) the name of v to a table called itemNames
I don't think I organized it correctly lmao, it wouldn't print the itemnames @coarse minnow
that means you dont have any children in cartItems that are frames
** You are now Level 8! **
when you add an item to the cart what kind of instance is it?
is it a text label or frame
HOLD ON
AHAHAHA
WOOPSIES
It's cus I made a folder
but now I don't have to anymore
🤩
YOOO IT'S WORKING
okay so
now
omg now what
idk 😭
@timid citrus @coarse minnow I want to say THANK YOU SO MUCH. I could not have done this with out you and sorry you had to handle my stupidity lmao. Thank you so so much.