Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i fix "attempt to index string with text"?

Asked by 2 years ago

How do i fix "attempt to index string with text"

this is the code that is being marked

-- Changing Display
    itemNameT.Text = toSelectIB.Name
    itemDescT.Text = toolData.Items[1].ToolTip

this is the full code if you need it

-- Player Stuff
local player = game.Players.LocalPlayer
local backpack = player.Backpack
local char = player.Character or player.CharacterAdded:Wait()

--Services
local ts = game:GetService("TweenService")
local sg = game:GetService("StarterGui")
local debris = game:GetService("Debris")

-- Disabling Backpack Gui
sg:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)


--Gui
local gui = script.Parent
local hotbarF = gui.Hotbar; hotbarF.Visible = true
local inventoryF = gui.Invetory; inventoryF.Visible = false; 

local itemDescriptionF = inventoryF.ItemDescription
local itemNameT = itemDescriptionF.Name
local itemDescT = itemDescriptionF.Description

local s1 = hotbarF.Slot1
local s2 = hotbarF.Slot2
local s3 = hotbarF.Slot3
local s4 = hotbarF.Slot4
local s5 = hotbarF.Slot5
local s6 = hotbarF.Slot6
local s7 = hotbarF.Slot7
local s8 = hotbarF.Slot8
local s9 = hotbarF.Slot9
local s0 = hotbarF.Slot0

local itemsSF = inventoryF.Items.ScrollingFrame
local closeB = inventoryF.CloseGui

local openB = gui.TextButton

local invSampleItem = itemsSF.Sample

-- Referencing Variables
local selectedItem = nil
local unselectColor = Color3.fromRGB(131, 131, 131)
local selectedColor = Color3.fromRGB(80, 80, 80)

-- Positions
local openP = UDim.new(0.5,0,0.5,0)
local closeP = UDim.new(0.5,0,1.5,0)



-- Scanning for Items
local function scanitems()

    --items list
    local items = {}

    --Scanning backpack 
    for i, tool in pairs(backpack:GetChildren()) do
        if tool.ClassName == "Tool" then
            table.insert(items, tool)
        end
    end


    --Scanning Character
    for i, tool in pairs(char:GetChildren()) do
        if tool.ClassName == "Tool" then
            table.insert(items, tool)
        end
    end

    -- Creating a new List
    local invItems = {}

    for i, tool in pairs(items) do
        if invItems[tool.Name] then
            invItems[tool.Name].Count += 1
            table.insert(invItems[tool.Name].Items, tool)

            else
            invItems[tool.Name] = {
                Count =1;
                Items = {tool};
            }
        end
    end
    return invItems
end

-- Updating Selected Items
local function updatedselected(toSelectIB, toolData)
    print(toolData.Items[1].Name .. " selected")
    -- Unselecting All
    local buttons = {}
    for i, itemButton in pairs(itemsSF:GetChildren()) do
        if itemButton.ClassName == "ImageButton" and not itemButton.Name == "Sample" then
            itemButton.BackgroundColor3 = unselectColor
        end
    end

    -- Selecting New
    toSelectIB.BackgroundColor3 = selectedColor
    selectedItem = toolData

    -- Changing Display
    itemNameT.Text = toSelectIB.Name
    itemDescT.Text = toolData.Items[1].ToolTip

end

--Removing Current Invetory Items
local function removeitems()
    for i, itemButton in pairs(itemsSF:GetChildren()) do
        if itemButton.ClassName == "ImageButton"and itemButton.Name ~= "Sample" then
            itemButton:Destroy()
        end
    end
end

-- Updating display
local function updateDisplay ()

    -- Clearing Out Current Invetory
    removeitems()


    --Getting Invetory Tools
    local invItems = scanitems()


    for toolName, toolData in pairs(invItems) do

        -- Cloning Sample
        local itemButton = invSampleItem:Clone()
        itemButton.Parent = itemsSF
        itemButton.Name = "Item"

        --Setting Display
        itemButton.CountDisplay.Text = toolData.Count .. "x" 
        itemButton.Image = toolData.Items[1].TextureId
        itemButton.Visible = true

        --Reselecting
        if selectedItem ~= nil and itemButton.Name ~= selectedItem.Items[1].Name then
            updatedselected(itemButton, toolData)
        end

        -- Connecting Buttons
        itemButton.MouseButton1Click:Connect(function()
            updatedselected(itemButton, toolData)

        end)

    end

end

--loop
while true do
    task.wait(5)
    updateDisplay()
end

1 answer

Log in to vote
0
Answered by 2 years ago

ItemNameT and ItemDescT already are strings as you can see here

local itemNameT = itemDescriptionF.Name
local itemDescT = itemDescriptionF.Description

so try this instead

-- Changing Display
    itemNameT = toSelectIB.Name
    itemDescT = toolData.Items[1].ToolTip

Hope this helps!

Ad

Answer this question