CFrame value being turned into a table when passed to a ModuleScript

I’m trying to send this CFrame value from a ServerScript to a ModuleScript function I have in ServerStorage.

--in ServerScript, calling the function in the ModuleScript
local cf = anothercf:ToWorldSpace(CFrame.new(0,0,-4.5))

local returndata = module:MakePart(cf)

However, the ModuleScript throws an error when I try to use the value to set the CFrame of a part, saying “(CFrame expected, got table)”

--in ModuleScript
function module.MakePart(cf)
	local part = Instance.new("Part", workspace)
	part.Name = "Box"
	part.Size = Vector3.new(9,9,9)
	part.Locked = true
	part.Anchored = true
	part.CanCollide = false
	part.Transparency = 0.5
	part.CFrame = cf --throws error at this line
end

I tried using the CFrame value in the same ServerScript and it worked.

local cf = anothercf:ToWorldSpace(CFrame.new(0,0,-4.5))

local testpart = Instance.new("Part", workspace)
testpart.CFrame = cf 

local returndata = module:MakePart(cf)

The part was created and positioned at that CFrame.
So I’m thinking it’s some behaviour of ModuleScripts that I don’t understand.

I believe the issue is caused by the : which causes the function to return self which is the module table instead of CFrame into the first argument.

Try doing dot notation instead:

local returndata = module.MakePart(cf)

From methods in this article.

1 Like