I am trying to have a part that, when in the vicinity of parts with a certain name, changes the partcolor of that part, and changes the properties of the children of that part. Currently I’m trying to use region3 based on the wiki page but I am not having any luck.
This is my code
local part = script.Parent
local min = part.Position - (0.5 * part.Size)
local max = part.Position + (0.5 * part.Size)
local region = Region3.new(min, max)
local parts = workspace:FindPartsInRegion3(region, part) -- ignore part
if parts.Name == "e81" then parts.BrickColor = BrickColor.new("Really black")
end
Building on @VegetationBush’s solution, you can loop through each descendant Workspace (higher Instances = slower):
local part = script.Parent
for _, Descendant in ipairs(workspace:GetDescendants()) do
if Descendant.Name == "e81" and Descendant:IsA("BasePart") then
if (Descendant.Position - part.Position).magnitude <= 5 then --put your range
Descendant.BrickColor = BrickColor.new("Really black")
end
end
end