Hi! I am making a custom collision system for a small game of mine, but I get the “Attempt to call a nil value” error. The error is on line 102. I know what the error means but I have no idea why I get the error, since I tested the code in “inCommand” and it worked perfectly. Could anyone explain me why I get the error or help me fix it?
Thanks in advance.
while true and wait(0.1) do
local collisions = computeCollision(player)
for i, v in pairs(collisions) do
local funcs = {
[-1] = "max",
[1] = "min"
}
player.Position = Vector3.new(
math[funcs[v.Position.X/math.abs(v.Position.X)]](player.Position.X, v.Position.X), -- line 102
player.Position.Y,
math[funcs[v.Position.Z/math.abs(v.Position.Z)]](player.Position.Z, v.Position.Z)
)
end
end
function computeCollision(part)
return game.Workspace:FindPartsInRegion3(Region3.new(Vector3.new(part.Position.X-part.Size.X/2, part.Position.Y-part.Size.Y/2, part.Position.Z-part.Size.Z/2),Vector3.new(part.Position.X+part.Size.X/2, part.Position.Y+part.Size.Y/2, part.Position.Z+part.Size.Z/2)),nil,5)
end
No it can’t, I think. The only thing that could be wrong is the “funcs[v.Position.X/math.abs(v.Position.X)]]” part, if it somehow isn’t equal to -1 or 1.
Ok I think I found the error. Its what I said: If the part’s position is 0,whatever,0 the equation is going to return nil, since there is only “-1” and “1” in the table. The didn’t dissapear so I’ll just use roblox physics until I find out what caused it. Thanks for the help.