local module = {}
-- IMPORTANT --
-- this module is made to replace the roblox collisions with a more reliable and possibly efficient solution. it's made to
-- solve the problem with HIGH speed collisions, not low speed. as in, there will be a visible delay with low speed but not
-- as apparent at high speeds. (please use for intended purpose)
local tool = script.Parent.Parent
local collidedis = 1 -- the distance at which the part is considered "colliding", the more the better at high speeds, depending on
-- the delay you have in the script that of which is calling this
module.CollisionPart = tool.Blade
local collisionPart = module.CollisionPart.Name
module.checkCollision = function(Part, collisionWith)
for _, Part in pairs(workspace:GetDescendants()) do
if Part:IsA("Part") or Part:IsA("UnionOperation") or Part:IsA("MeshPart") or Part:IsA("Wedge") or Part:IsA("Cylinder") then
if (module.CollisionPart.Position - Part.Position).Magnitude < collidedis and Part.Name ~= collisionPart then
collisionWith = Part
return collisionWith
elseif (module.CollisionPart.Position - Part.Position).Magnitude > collidedis then
-- idk do whatever you want here
end
end
end
end
return module
Collision | Server Script
local ImprovisedCollis = require(script.Parent.ImprovisedCollision)
local interval = 0.01
while wait(interval) do
ImprovisedCollis.checkCollision(ImprovisedCollis.collisionWith)
print(ImprovisedCollis.collisionWith)
end
I’m basically trying to get the collisionWith variable from the module script function.
(Oh yeah btw, it prints nil in the server script.)
Create a new key/field in the ‘module’ table and assign it the result of the operation being looped. Then all you need to do is index this key/field in the requiring script to fetch the latest value (of the previously mentioned operation).
local module = {}
-- IMPORTANT --
-- this module is made to replace the roblox collisions with a more reliable and possibly efficient solution. it's made to
-- solve the problem with HIGH speed collisions, not low speed. as in, there will be a visible delay with low speed but not
-- as apparent at high speeds. (please use for intended purpose)
local tool = script.Parent.Parent
local collidedis = 1 -- the distance at which the part is considered "colliding", the more the better at high speeds, depending on
-- the delay you have in the script that of which is calling this
module.CollisionPart = tool.Blade
module.collisionWith = nil
local collisionPart = module.CollisionPart.Name
module.checkCollision = function(Part, collisionWith)
for _, Part in pairs(workspace:GetDescendants()) do
if Part:IsA("Part") or Part:IsA("UnionOperation") or Part:IsA("MeshPart") or Part:IsA("Wedge") or Part:IsA("Cylinder") then
if (module.CollisionPart.Position - Part.Position).Magnitude < collidedis and Part.Name ~= collisionPart then
module.collisionWith = Part
return module.collisionWith
elseif (module.CollisionPart.Position - Part.Position).Magnitude > collidedis then
-- idk do whatever you want here
end
end
end
end
return module
I tried that but there isn’t any part variable so there’s not much for the script to print.
I found another solution to my problem. (same code i had originally in the module)
local ImprovisedCollis = require(script.Parent.ImprovisedCollision)
local interval = 0.01
while wait(interval) do
ImprovisedCollis.checkCollision(nil, script.Parent.Parent.Blade)
if ImprovisedCollis.checkCollision() ~= nil then
print(ImprovisedCollis.checkCollision())
end
end