Here’s what I got:
If anyone needs/is interested in how I did it, here it is:
local Workspace = game:GetService("Workspace")
local ipairs = ipairs
local task = task
local Vector3 = Vector3
local CFrame = CFrame
local tick = tick
local print = print
local parts = {...}
local function handleCollisions(part: Part, partsInPart: {BasePart})
for _, somePart in ipairs(partsInPart) do
if somePart.Anchored then
continue
end
local partPosition = part.Position
local somePartPosition = somePart.Position
local lookVector = CFrame.lookAt(
partPosition,
somePartPosition - (Vector3.yAxis * somePartPosition.Y) + Vector3.yAxis * partPosition.Y
).LookVector
local velocityModule = somePart.AssemblyLinearVelocity.Magnitude
if velocityModule > 12 or velocityModule < 12 then
velocityModule = 12
end
local velocity = lookVector * velocityModule
somePart.AssemblyLinearVelocity += (lookVector * velocityModule)
end
end
local function iterate()
for _, part in ipairs(parts) do
local partsInPart = Workspace:GetPartsInPart(part)
if not partsInPart or #partsInPart <= 0 then
continue
end
task.spawn(handleCollisions, part, partsInPart)
end
end
while task.wait() do
iterate()
end
I usually use local variables for global ones. Because I remember reading that this seems to speed up lua. Although I’m not sure if this works in luau. I’ve done a bit of testing and the results are very similar, so I’m not sure if I’m speeding up the code.
Thank you!