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

Why does this scrip keep returning a nil error when I try to get my only stringValue's value?

Asked by 4 years ago

My goal is to have this print out a message in a gui and this is code from my main game script so it can end up guiding the game but I need a place to keep the players informed on how my game works and how long each round has. Line 5 has the place the nil error is:

local display
game.Workspace:FindFirstChild("valueHold", display)

wait (10)
display.Value  = "Welcome to Game. thanks for joining"
print "Initial Message was set"
--wait(10)
--display.Value = "Game still being developed, stay tuned"
--print "Secondary message set"

local display = script.Parent
local messa
game.Workspace:FindFirstChild("StringValue", messa)
local messageToDisplay = messa.Value

local function messageChange(messageToDisplay)--if the value is changed in the valueHold then do the following
    local messageTyped = {} --attempts to put message into a table
        for i,sub in pairs(messageToDisplay) do 
        messageTyped[i] = messageToDisplay:sub(i,i)
        print (messageTyped)
        end

    for i,letter in pairs(messageTyped) do --loop set up
        local finalSend
        finalSend = finalSend + letter --for each letter in message write and then the next and so on
        display.Text = finalSend
        wait(.2)
        end
        print "Message Successfully Displayed"
end

Thank you for the help! P.S. I know the code is a little messy, but I'm learning and it's in the works :)

1 answer

Log in to vote
1
Answered by
DesertusX 435 Moderation Voter
4 years ago

You defined the value after getting it. Therefore, it is nil. To fix this, just change line 1 to:

local display = script.Parent

instead.

Also, remove line 11, we don't need it because it is already defined.

By the way, are the hyphens on line 7 to 9 intentional?

Hope this helps!

Don't forget to accept this answer if it does!

0
Yes it was itentional! Have to put that later on haha thanks! snoppyploptart 59 — 4y
0
No problem! Always happy to help! DesertusX 435 — 4y
Ad

Answer this question