I have a script that constantly checks the region around a player and sets the velocity of any non-zero velocity parts at a velocity of zero. While it works definitely a bit, it does not detect the parts accurately enough, with moving parts able to keep going at their velocity when they are supposed to be stopped. I am asking how I can fix that provided with what I have as scripted as the problem is how Region3 isn’t detecting parts commonly even when parts are in it. The parts I tested have a velocity of 100 but I do want my script to work for any high speed objects.
local hrp = humanoid.RootPart
loop = game:GetService("RunService").Heartbeat:Connect(function()
local vector1 = (hrp.CFrame * CFrame.new(-8, -8, -8)):PointToWorldSpace()
local vector2 = (hrp.CFrame * CFrame.new(8, 8, 8)):PointToWorldSpace()
local region3value = Region3.new(vector1, vector2)
local region3find = workspace:FindPartsInRegion3(region3value)
for _, v in pairs(region3find) do
if v.Anchored ~= true and (v.Velocity).Magnitude > 0 and v.Parent ~= hrp.Parent then
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= workspace then
v = v.Parent.Humanoid.RootPart
end
v.Velocity = Vector3.new(0, 0, 0)
end
end
end)
Solution has been posted. In this script, the player’s orientation influences the Region3 script’s ability to find parts in a constant unorientated box registering parts in Region3 which is the cause of the problem due to using CFrame.