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

Why does this value turn nil when I pass it into a function?

Asked by 5 years ago

So in my script, I call seperateCFrame and it ends up giving me an error on the loop because it's trying to find the length of a nil object (cfrm) thinking its a string. When I do a print test on it I find that before I call the function it prints fine, but as soon as I call it the parameter turns nil. Why is that?

function seperateCFrame(cfrm)
    print(cfrm)             -- Prints nil
    local localSeperator = ","
    local element = ""
    local newCFrame = {}

    for i = 1,string.len(cfrm) do   -- Error trying to get len of nil value
    -- Other stuff...

local data = serverdata
    for i,v in pairs(data) do
        print("Test: "..v," | ",v[3])   -- Prints everything fine
        local cframe = seperateCFrame(v[3])
        -- Other stuff...

0
 What does it print and what is v[3] User#5423 17 — 5y
0
Problem is most likely on `v[3]`. Explain what that is.  Zafirua 1348 — 5y
0
v[3] is a string value of a tostring(part.CFrame) climethestair 1663 — 5y
0
What is the output for line 12. User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Sorry about this facepalm, but v is actually a string value, which is why v[3] was nil. I got confused by the print because I used the same symbol to separate data in the string as I did to separate the output of v and v[3].

Ad

Answer this question