How would I make an attribute parent name go to a string?

Hey devforum! I’m trying to make a tycoon and I’m running into a bit of a problem. I’m trying to make it so above a button there’s some text and that says the name of the item they are purchasing and the cost, but it keeps saying
image

Heres my script

Button.BillboardGui.TextLabel.Text = getItem(Button:GetAttribute('ItemId')).Name.." - "..Item:GetAttribute('Cost')

There’s also Id’s inside of the buttons and Items, and another tycoon in replicated storage.

2 Likes

You can create a new attribute to the button and call it ItemName.
or you can use an algorithm like this, give me a moment ^

1 Like

Basically your getItem function returned nil. Try looking into it.

1 Like
local itemNames = {
	[ITEM_ID] = "ITEM_NAME"
}

local function GetItemName(itemID)
	return itemNames[itemID]
end

Button.BillboardGui.TextLabel.Text = GetItemName(Button:GetAttribute('ItemId'))
1 Like

Would I have to put all the “item names” into itemNames?

Also here is my getItem function

local function getItem(itemId)
	for _, Item in Items:GetChildren() do
		if Item:GetAttribute('Id') == itemId then
			return Item
		end
	end
end

I don’t really see anything wrong with it

It’s weird how you use two attributes for similar data? That is, why do you use “ItemId” and “Id” for representing item id?

I figured it out, there was something wrong with my getItem function

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.