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