I am currently trying to restrict people from going below a certain angle doing a certain action.
Here’s a snippet code that is active when doing the function.
local maxAngle = math.acos(math.pi/2)
function Add(a, b, c, d)
...
if leftDot >= maxAngle and rightDot >= maxAngle then
return function()
adjust(wall, leftWall)
adjust(rightWall, wall)
walls[wall] = true
end
end
local function rel()
...
local placeA = Add(a,b,c,d)
local placeB = Add(a,c,b,d)
if placeA and placeB then
--Code
else
end
end
It’s hard to see the issue, since you’re looking for both parameters to be true, but we can’t see where things are executing so we can’t help beyond that.
A, B, C, D is not correlated with the code that is active in the bug.
But nontheless, if it helps
local thresh = math.acos(math.pi/2)
local function addToPoll(polls, poll, otherPoll, model)
local walls = getWalls(polls, poll)
local dir = (poll - otherPoll).Unit
local rightDir = dir:Cross(UP)
local right, left = model.Wall1, model.Wall2
local toRight = right.Position - left.Position
if toRight:Dot(rightDir) < 0 then
right, left = left, right
end
local wall = {
length = {
left = 0;
right = 0;
};
model = model;
right = right;
left = left;
dir = dir;
rightDir = rightDir;
}
if not next(walls) then
walls[wall] = true
return
end
local leftIsFound
local leftDot
local leftWall
local rightIsFound
local rightDot
local rightWall
for otherWall in next, walls do
local dot = dir:Dot(otherWall.dir)
local isRight = rightDir:Dot(otherWall.dir) < 0
if isRight then
if not rightIsFound or not rightDot or dot > rightDot then
rightIsFound = true
rightDot = dot
rightWall = otherWall
end
if not leftIsFound and (not leftDot or dot < leftDot) then
leftDot = dot
leftWall = otherWall
end
else
if not rightIsFound and (not rightDot or dot < rightDot) then
rightDot = dot
rightWall = otherWall
end
if not leftIsFound or not leftDot or dot > leftDot then
leftIsFound = true
leftDot = dot
leftWall = otherWall
end
end
end
if leftDot >= thresh and rightDot >= thresh then
return function()
adjust(wall, leftWall)
adjust(rightWall, wall)
walls[wall] = true
end
end
end
local function placeWall()
if mouseDown then
templatePole.Transparency = 0.65
local wall = wallModel
wall.Parent = workspace.Walls
wall.Wall1.Transparency = 0
wall.Wall2.Transparency = 0
local placeA = addToPoll(polls, pollA, pollB, wall)
local placeB = addToPoll(polls, pollB, pollA, wall)
if placeA and placeB then
placeA()
placeB()
endWallPlacement()
else
print("destroy")
wall:Destroy()
endWallPlacement()
end
mouseDown = false
end
end
isn’t the reason that place a and b are nil is because they are not actually calling the returned function? it seems like you aren’t calling the function that you returned
function Add(a, b, c, d)
if leftDot >= maxAngle and rightDot >= maxAngle then
local func = function()---Defined here
adjust(wall, leftWall)
adjust(rightWall, wall)
walls[wall] = true
end
return func()----Its being called/returned
end
end
No this doesn’t work either. I have however come to the conclusion that the wall has nothing to compare its angle with initially (or rather in the beginning) so it automatically turns nil. I have an awesome human being looking into it right now though. I will come back with an answer!
Might be due to that part? Like you’re returning nil in the “addToPolls” function before getting to the return segment for the function. It could be that it returns that before getting to it.