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

Is there any way to put variables inside paths and make the script use the variable? (READ)

Asked by
chasedig1 115
5 years ago

I'm making a questionnaire game in ROBLOX, and I have a StringValue. I want to randomly select an answerbox so people aren't like "top left is always correct". I have a table. The table values are the names of the incorrect/correct answers. When I run the game, it's trying to use the string form: "AnswerPositions" instead of the variable form, which could be "Correct", "Incorrect1", "Incorrect2" or "Incorrect3". This is because it isn't checking and using the variable form. How do I make it do this?

Here is my code for reference:

function RandomizeTable(tbl) --Table Randomizer Function
    local returntbl={}
    if tbl[1]~=nil then
        for i=1,#tbl do
            table.insert(returntbl,math.random(1,#returntbl+1),tbl[i])
        end
    end
    return returntbl
end
    AnswerPositions={"Correct","Incorrect1","Incorrect2","Incorrect3"}
AnswerPositions=RandomizeTable(AnswerPositions)

local AnswerPositions0 = Question.AnswerPositions[0]
local AnswerPositions1 = Question.AnswerPositions[1]
local AnswerPositions2 = Question.AnswerPositions[2]
local AnswerPositions3 = Question.AnswerPositions[3]

print("The answer positions are: "..AnswerPositions[1],AnswerPositions[2],AnswerPositions[3],AnswerPositions[4])

AnswerBoard1.Text.Answer.Text = Question.AnswerPositions[0].Value
AnswerBoard2.Text.Answer.Text = Question.AnswerPositions[1].Value
AnswerBoard3.Text.Answer.Text = Question.AnswerPositions[2].Value
AnswerBoard4.Text.Answer.Text = Question.AnswerPositions[3].Value

Here is my error message for reference: 00:40:30.926 - AnswerPositions is not a valid member of StringValue

Get me a working fix and I'll mark your post as correct!

0
can you send me an image of Question's hierarchy? brokenVectors 525 — 5y

1 answer

Log in to vote
0
Answered by
chasedig1 115
5 years ago

Answer has been found! You need to put [] around the variable being used. Imagine there was a variable that had the name of the player object you wanted to delete. You would do this: game.Workspace[player]:Destroy() I solved this question by myself with a stack overflow article. Article link

Thanks for helping and reading anyway!

Ad

Answer this question