I’ve been working on an inventory system that displays item details when a slot is clicked.aka description. I have this module script that holds on to item details for use by multiple scripts. When I try to get the text to be displayed, an error shows that
[15:39:30.470 - Players.KawaiiX_Jimin.PlayerGui.menu.inventoryframe.slotholder.scrollinven.Butter.click.LocalScript:14: bad argument #3 to 'Text' (string expected, got nil)]
I want to know why this error occurs even though the description is a string. This is the current code and an example of an item from the module script
Text Script(local)
local player = game.Players.LocalPlayer
local gui = player.PlayerGui
local infoHolder = gui.menu.inventoryframe.infoholder
local itemdesc = infoHolder.itemdesc
local itemname = infoHolder.itemname
local equip = infoHolder.equip
local unequip = infoHolder.unequip
local itemdb = require(game.ReplicatedStorage.itemDatabase)
local name = script.Parent.Parent.Name --item name
script.Parent.MouseButton1Click:Connect(function()
itemname.Text = name
itemdesc.Text = name["desc"] --getting item description from module
--this is where the error occurs. I want the text to change into the item's description but the above error happens
end)
If you have time, how would I get an image from the module script if I want to display it on an ImageLabel if the code as follows is like this - button.itemImage.Image = v.Name[“desc”]
From the looks of it name is just a string yet you are trying to access desc in it like its a table.
You can “technically” index a string like its a table because of its functions like string:len() etc but if its not one of the string manipulator functions, it just returns nil. So name["desc"] = nil in this case.
If your itemdb entries are keyed by their name then you can do itemdb[name]["desc"] otherwise you might have to iterate through the itemdb and find the one with the right name value.
For your second question just set the ImageLabel.Image property to the assetid link. (In code this is just a string like in your example) ImageLabel.Image = DBEntry.image
As a side note you don’t always need the [“”] when declaring table indexes. You mainly only do when the key has a space in it or you are trying to use a variable as the index.
{
name = "Mushroom",
image = "rbxassetid://4082219038",
value = 25,
model = models:WaitForChild("Mushroom"),
desc = "Not a toadstool"
},
is valid too. So is itemdb[name].desc in my earlier example but I chose to use ["desc"] for consistency in that case.
The output states an error which I have been trying to figure out [17:00:57.393 -Players.KawaiiX_Jimin.PlayerGui.menu.inventoryframe.slotholder.scrollinven.Butter.click.LocalScript:13: attempt to index field '?' (a nil value)]
What does your whole itemdb look like? Your entries are gonna need string keys if you want to access it like that. That error is telling you nameValue.Value whatever that represents as a key in table has a nil value so when you try to access desc there’s nothing to access.
Mushroom = {
name = "Mushroom",
image = "rbxassetid://4082219038",
value = 25,
model = models:WaitForChild("Mushroom"),
desc = "Not a toadstool"
},
Something like that. Otherwise you need to loop through all of the entries to find what you are looking for. So if NameValue.Value = “Mushroom” then itemdb[NameValue.Value] would return the table representing that.