What do you want to achieve?
I want to go through all parts in the workspace and then change the material of the part which size is similar to the one specified.
What is the issue?
The script doesn’t find any parts, however there are some parts that are the same size.
What solutions have you tried so far?
I have tried to look on the Developer Hub, but I found nothing that could solve my problem.
This is my code so far.
local s = Vector3.new(0.3, 2.7, 0.1)
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") or v:IsA("BasePart") then
if v.Size == s then
v.Material = Enum.Material.Grass print("Similar")
end
end
end
I didn’t run into any problems myself when testing it.
As for checking similar sized parts, take a look at the below code. The difference will be 0 when the size of the part you’re checking is the CHECK_SIZE. The ALLOWANCE is how far you can stray away from 0.
Hope this helps.
local ALLOWANCE = 1.5
local CHECK_SIZE = Vector3.new(4, 1, 2)
for _,v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") and v.Material then
local difference = v.Size.Magnitude - CHECK_SIZE.Magnitude
if difference <= ALLOWANCE and difference >= -ALLOWANCE then
v.Material = Enum.Material.Grass
end
end
end