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

Error with calling function: Attempt to call a nil value?

I am trying to get a value with a string variable ValueType, and a table variable storing all of the values that will make up an unknown value. Say ValueType is "Vector3" and newtable is 1, 2, and 3. My goal is to get the value Vector3.new(1, 2, 3). Right now I have a nil value from this line below. How do I fix this?

local finalinput = ValueType["new"](newtable)

Thanks!

2 comments

0

I think I understand what you're asking, but am still a little confused. Can you explain what you are trying to do with this?

0

I am trying to make it so you can change properties of an object in a plugin I am making. Working on the value part.

1 answer

I am not sure why you would need to do this, but you could create a function that converts a string to a class (Vector3, CFrame, Instance, etc).

local function stringToClass(string)
	if string == "Vector3" then
		return Vector3
	elseif string == "CFrame" then
		return CFrame
	elseif string == "Instance" then
		return Instance
	end
	--- continue this for all classes you expect 
end

local class = stringToClass(ValueType)
local finalInput = class.new(newtable[1], newtable[2], newtable[3])

2 comments

0

That's what I was trying to avoid.

0

Oh I see. I think this is an example of the X, Y problem http://xyproblem.info/

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