W001 Unknown Global Error

I am making a riddle game, and using variables to give a random riddle.
It gives me an W001 Unknown Global Error on both lines 3 and 5.
Script-
Riddle = math.random (1, 2)
if Riddle == 1 then
RiddleAnswer = PrisonerHatRiddle
if Riddle == 2 then
RiddleAnswer = BridgeRiddle
end
end
local function RiddleTest()
print (“I have just the riddle for you, yes indeed I do.”)
print (“This little riddle is made by us, made for you.”)
print (“Today’s little riddle is…”)
print (RiddleAnswer)
end
RiddleTest()

2 Likes
local RiddleAnswer
local Riddle = math.random(1, 2)

if Riddle == 1 then
    RiddleAnswer = "PrisonerHatRiddle"
elseif Riddle == 2 then
    RiddleAnswer = "BridgeRiddle"
end

local function RiddleTest()
    print("I have just the riddle for you, yes indeed I do.")
    print("This little riddle is made by us, made for you.")
    print("Today’s little riddle is…")
    print(RiddleAnswer)
end

RiddleTest()

If you have strings, you need to type them out with quotations " ". Also, since you’re making the RiddleAnswer variable not fully to the left, you need to define it like I did.

5 Likes

Those marks are true quotation marks on the print statements, instead of programming quote marks.

and are not valid. You need " at the start and end.

2 Likes
local RiddleAnswer
local Riddle = math.random(1, 2)
if Riddle == 1 then
    RiddleAnswer = "PrisonHatRiddle"
elseif Riddle == 2 then
    RiddleAnswer = "BridgeRiddle"
end
local function RiddleTest()
    print("I have just the riddle for you, yes indeed I do.")
    print("This little riddle is made by us, made for you.")
    print("Today's little riddle is...")
    print("RiddleAnswer")
end
RiddleTest()
2 Likes

Sorry, I had copied and pasted what he originally wrote. I changed it right when you posted that

2 Likes

No worries, it’s sort of aimed at OP too so they understand :slight_smile:

3 Likes

Thanks! It works perfectly! Much appreciated!

2 Likes