I'm trying to make a function that returns false only if ANY part in workspace is within a certain range of a part called CSprout. My attempt is below and I'm not sure what I need to do to make it work. This isn't the whole script, just the function I'm trying to fix. If I need to clarify anything let me know. Thanks!
local seed = script.Parent local position = seed.Position local RANGE = 5 function spaceCheck(CSprout) local OTHER = game.Workspace:GetChildren() for index, child in pairs(OTHER) do print(OTHER.Name) if OTHER:IsA("Part") and (CSprout.Position - OTHER.Position).magnitude < RANGE then return false else return true end end end
You're checking if OTHER is a Part, while OTHER is actually the contents of Workspace. You need to check for child instead, such that:
function spaceCheck(CSprout) local OTHER = game.Workspace:GetChildren() for index, child in pairs(OTHER) do print(child.Name) if child:IsA("BasePart") and (CSprout.Position - child.Position).magnitude < RANGE then return false else return true end end end
I also changed Part to BasePart to work with wedges and other parts under the BasePart category.