Error relating making a table value based on a function

Creating a class, and I wanted to try setting my table value to a function that would run when I call the value (I don’t know if that is optimal). When I try to call the table for later use I get an error stating I am attempting to get the length of a function value. Is what I am trying to achieve impossible?

local Debris = game:GetService("Debris")
local Run = game:GetService("RunService")

local Bolt = {}
Bolt.__index = Bolt

local Tool = script.Parent.Parent

function, EndPos, Segments)
	local NewBolt = setmetatable({}, Bolt)
	NewBolt.StartPos = StartPos
	NewBolt.EndPos = EndPos
	NewBolt.Segments = Segments
	NewBolt.Points = function() --Table in question
		print("Points being created")
		local RNG =
		local Points = {}

		for i = 1, Segments do
			if i == 1 then
				Points[#Points+1] = StartPos
			elseif i == 10 then
				Points[#Points+1] = EndPos
				local Position = StartPos + ((EndPos - StartPos).Unit*i*(EndPos - StartPos).Magnitude / Segments)
				local Offset =,1),RNG:NextNumber(-1,1),RNG:NextNumber(-1,1))
				Points[#Points+1] = Position + Offset

		return Points
	return NewBolt

function Bolt:Draw()
	local Folder = Tool:FindFirstChild("LightningBolt") or"Model", Tool)
	Folder.Name = "LightningBolt"
	local Points = self.Points --Error
	for i = 1, #Points do
		if Points[i+1] ~= nil then
			local Segment = script.Bolt:Clone()
			Segment.Size =, 0.2, (Points[i]-Points[i+1]).Magnitude)
			Segment.CFrame =[i]:Lerp(Points[i+1],0.5), Points[i+1])
			Segment.Parent = Folder
	return Folder

return Bolt

Try changing local Points = self.Points to local Points = self.Points()

The reason why you’re having the error is that you are calling the function itself, not the result of the function.

1 Like

Ahhhhhhh, I missed that. That time of the night I guess, thanks so much!