Attempt to index string with 'Text'

Hi,

so while trying to apply Attributes to certain store Items, trying to Apply a string type Attribute to a TextLabel's Text gives me an error.

I still haven’t fully setup the System tho

for number, Asset in Frame:GetChildren() do
	if Asset:IsA("Frame") then
		
		if Asset:GetAttribute("Price") >= 1000 then
			local Div = Asset:GetAttribute("Price")/1000
			Asset.Buy.Text = "R$"..Div.."K"
		else
			Asset.Buy.Text = "R$"..Asset:GetAttribute("Price")
		end
		Asset.Desc.Text = Asset:GetAttribute("Desc") -- Error Line
		Asset.Buy.Activated:Connect(function()
			MarketPlaceService:PromptProductPurchase(Player, Asset:GetAttribute("Asset"))
		end)
	end
end

The Items Attribute’s and Children:

Screenshot (94)

Screenshot (95)

I am currently only testing with one Frame However, not multiple,
Why am I getting this Error?

1 Like

Hello! So the error “attempt to index string with ‘Text’” means that you “Desc” in Asset.Desc.Text is being read as a string value and not the instanced TextLabel “Desc”. I believe your Frame T1 is the one housing all of the attributes? If it is you could try adding…

Asset:WaitForChild("Desc").Text

This is because “Asset” in the FOR loop is every Frame that is a child of “Frame” in this case.

This is the function I made to test your code and organization and I didnt appear to have any issues with it. I added one attribute to the frame T1 called “Desc” with the value “Test” and it changed the label text to “Test”.

local function TestFunc()
	for number, Asset in script.Parent:WaitForChild("Background"):GetChildren() do
		if Asset:IsA("Frame") then
			
			Asset:WaitForChild("Desc").Text = Asset:GetAttribute("Desc")
			
		end
	end
end

TestFunc()

Let me know if this doesnt fix it and I’ll keep experimenting.

2 Likes

That’s not the Issue, The Script is able to find the TextLabel's Text , for some reason its giving me this error

Plus, there is a Difference between

Asset.Desc.Text = Asset:GetAttribute(Asset)
-- and:
Asset.Desc.Text = Asset:GetAttribute("Asset")

This is also not the Issue

(I misread what you said, but it still didn’t fix it :frowning: )

1 Like

I fixed the issue, I deleted the Attribute and then recreated it which Somehow fixed it, Thanks for your help @OurAuthority, thanks for trying to fix the issue :slight_smile:

1 Like

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