Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I fix this part finding function?

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

1 answer

✓ Accepted answer

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.

1 comment

1

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.