Module keeps returning nil, even though it has the right value

Hello! I’ve been recently working on a placement system, and I ran into this bug, for some reason, the module started returning nil to the script, despite the fact that it has the right CFrame in its script, I didn’t even edit the script whatsoever, as it was working perfectly, and it just randomly stopped working, and now I am not able to fix it.

Thanks in advance!

The main script, it gets nil for some reason

game:GetService("RunService").RenderStepped:Connect(function(dt)
	if game.Players.LocalPlayer.Character.Stats.InsideHouse.Building.Value == true and pickedsomething == true and model ~= nil then
		local cf = placement:CalcPlacementCFrame(model, mouse.Hit.p, rotation)
		print(cf)
		if cf ~= nil then 
			model:SetPrimaryPartCFrame(cf)
		end
	end
end)

Module, it gets the right CFrame

function Placement:CalcPlacementCFrame(model, position, rotation)
	local cf, size = self:CalcCanvas()

	local modelSize = CFrame.fromEulerAnglesYXZ(0, rotation, 0) * model.PrimaryPart.Size
	modelSize = Vector3.new(math.abs(modelSize.x), math.abs(modelSize.y), math.abs(modelSize.z))

	local lpos = cf:pointToObjectSpace(position);
	local size2 = (size - Vector2.new(modelSize.x, modelSize.z))/2
	local x = math.clamp(lpos.x, -size2.x, size2.x); --Forward?
	local y = math.clamp(lpos.y, -size2.y, size2.y); --Side
	--local z = math.clamp(lpos.y,position.Y, size.y)

	local g = self.GridUnit
	if (g > 0) then
		x = math.sign(x)*((math.abs(x) - math.abs(x) % g) + (size2.x % g))
		y = math.sign(y)*((math.abs(y) - math.abs(y) % g) + (size2.y % g))
	end

	local zthing = -modelSize.y/2
	local z = position.Y+zthing
	local finalz = math.clamp(z, z, z)
	return cf * CFrame.new(x, y, -modelSize.y/2) * CFrame.Angles(-math.pi/2, rotation, 0)
end

Try printing out the returning value before doing return

I actually did that, and it has the right value, but when it is returned, it is nil for some reason.

Try printing out all the variables inside the :CalcPlacementCFrame function.

Try printing the second return argument by doing that:

local returnA,returnB = module:FunnyFunction()
print(returnA,returnB)
1 Like

Did that, too.

For some reason, this made the function work, despite the fact that the second is nil.

local returnA,returnB = module:FunnyFunction()
print(returnA,returnB)

This shouldn’t have changed anything, as you suggested. There must be an issue with the values you’re passing as arguments to the module’s instance method.

Is it possible that something is nil on the local script’s side?

1 Like

There is definitely an issue, but I seem to be unable to locate it, I’ve printed all the values in both module and the local script, and they seem to be alright.

By any chance are you passing information between the client and the server? Some of those values are scrubbed.

As I mentioned, I am passing information between a ModuleScript and a LocalScript.

Print the arguments on the local script’s side and then the corresponding parameters on the module script’s side.

I have already done that, it seems to correspond again.