Introduction
I use Region3 to detect players and objects. These Region3 are not premade but created with a tool like this:
Code
local Players = game:GetService("Players")
local region
local part
local localPlayer = Players.LocalPlayer
local backpack = localPlayer:WaitForChild("Backpack")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false
tool.Parent = backpack
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
region = Region3.new(Vector3.new(mouse.X, 0, mouse.Y), Vector3.new(mouse.X, 50, mouse.Y))
part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.Size = Vector3.new(10, 50, 10)
part.CFrame = mouse.Hit --return CFrame
part.CanCollide = false;
part.Orientation = Vector3.new(0, 0, 0) --Comment this and you will understand...
part.Color = Color3.new(255, 20, 60)
part.Name = "Pipe"
end
end)
end)
while true do
wait()
local partsInRegion = game.workspace:FindPartsInRegion3(region, part, 100)
for i, part in pairs (partsInRegion) do
print("Player is in area")
end
end
in this part
while true do
wait()
local partsInRegion = game.workspace:FindPartsInRegion3(region, part, 100)
for i, part in pairs (partsInRegion) do
print("Player is in area")
end
end
Which is from another code I made where I tested the concept of Region3 on a LocalScript I try to make the detections.
local region = Region3.new(Vector3.new(1, 1, 1), Vector3.new(10, 10, 10))
local part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.CanCollide = false
part.CFrame = region.CFrame
part.Size = region.Size
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3(region, part, 100)
for i, part in pairs (partsInRegion) do
print("Player is in area")
end
end
print("end")
Idea behind all of this
I want to create a "thin" Region3 that gets the names of certain objects in its path (not infinite) and for now I am not going to use a Ray.
