I want to union all of the parts with the same Y axis and have a certain value (Weight) in a model, but i'm not sure how to do it
local Print = workspace.GameValues.MagicDebug local roundDecimals = function(num, places) --This Part Works (You don't need to see it and it's just a visual thing) end if Print then print(script.Parent.Name.."'s Union Function Begin") end for i, part in pairs(script.Parent:GetChildren()) do if part:WaitForChild("Weight") then part.Name = roundDecimals(part.Position.Y, 2) end end if Print then print(script.Parent.Name.."'s Union Function End") end
(It does name the parts their Y but it's more exact if I were to check their Y property)
I created this function for you.. it's pretty straightforward and basically just creates a dictionary with all the different positions inside the model with a table inside of each value naming all the parts.
function findAllPartsWithY(MODEL) local t = {} -- create an empy table local function roundDecimals(num, places) -- simple rounding function return tonumber(string.format("%." .. (places or 0) .. "f", num)) end for i,v in pairs(MODEL:GetChildren()) do if v:FindFirstChild("Weight") then local y = roundDecimals(v.Position.Y, 2) t[tostring(y)] = {} end end for i,v in pairs(MODEL:GetChildren()) do if v:FindFirstChild("Weight") then local y = roundDecimals(v.Position.Y, 2) if t[tostring(y)] then table.insert(t[tostring(y)], v.Name) end end end return t end findPartsWithSameY(MODEL) -- replace MODEL with whatever model you're using this on
Here is an example of it being used
Please accept my answer if this solved your problem.
Let me know if you have any questions.