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

How to refer to a table using a string?

Asked by 2 years ago

Hi.

Intro I want to refer to a table through a string. Here is the code for a better explanation:

local CrawlText = {}
CrawlText[1] = "Looks like I can crawl through this gap."
CrawlText[2] = "I must be careful."

function showNarration(Object)  --For example, Object is "Crawl"
    local tableName = tostring(Object.."Text")
    local narrateText = tableName
    if #narrateText > 1 then
        for i = 1,#narrateText do
            text.Text = narrateText[i]
            shownarrategui(4)
            wait(4)
        end
    else
        text.Text = narrateText[1]
        shownarrategui(6)
    end
end

Narrate.OnClientEvent:Connect(showNarration)

Problem It doesn't recognize narrateText as a table. And it says "Expected string, got nil." I can't seem to find any question regarding this problem anywhere. And I'm stuck. Any help would be appreciated. Thanks.

Answer this question