Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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...

4 comments

0

 What does it print and what is v[3]

0

Problem is most likely on v[3]. Explain what that is. 

0

v[3] is a string value of a tostring(part.CFrame)

0

What is the output for line 12.

1 answer

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].

This discussion is preserved as it was. New answers, comments, and votes are closed.