So I am using a client script to cast a ray so it can detect if something touches the part but it would cause a lot of lag.
local RunService = game:GetService("RunService")
local model = script.Parent
model.Parent:WaitForChild(model.Name)
local Parts = model:WaitForChild("Parts") -- folder
local function onTouched(part, otherPart)
script.DestroyWeld:FireServer(part)
end
----------------------------------------------------------------------------------------------------------------------------------
local function raycastPart(part)
local rayOrigin = part.Position
local rayDirection = ((part.Position).Unit * part.Size.Magnitude) * 2
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
local hit = raycastResult.Instance
onTouched(part, hit)
end
end
RunService.Heartbeat:Connect(function()
for i,v in ipairs(Parts:GetDescendants()) do
if v:IsA("BasePart") then
raycastPart(v)
end
end
end)
You can simply raycast every time your mouse moves, and then simply see if that’s the part you’re looking for. You don’t need to go through the list every time.
If that’s the case, you could always just check if there’s a sudden drop in velocity using differences between 2 Vector3s and checking that difference’s Magnitude.