Function returning false

Hey!, I have a problem with my script which detects if a part or a model has a children.
image

The error I have is that when I try to detect if the model or part has a children it always tells me that it does not have any object, because it prints false

Here is the code of my module script:

local module = {}

module.CheckIfHasObj = function (obj, HasObj)
	if obj:IsA("Model") then 
		if #obj:GetChildren() > 0 then
			return HasObj == true

		else
			return HasObj == false
		end
	elseif obj:IsA("Part") or obj:IsA("MeshPart") or obj:IsA("SpawnLocation") then
		if #obj:GetChildren() > 0 then -- more	> 0 
			return HasObj == true

		elseif #obj:GetChildren() < 0 then -- no obj
			return HasObj == false
		end


	end

end



return module

ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FunctionsSearch = require(ReplicatedStorage.FunctionsCheck)

local function CheckObj(obj)

	local function CheckStatus(HasObj)
		if FunctionsSearch.CheckIfHasObj(obj, true) then
			return HasObj == true
		elseif FunctionsSearch.CheckIfHasObj(obj, false) then
			return HasObj == false
		end


	end
	print(CheckStatus())

	
	if CheckStatus() == true then
		print("Has obj")
	end

	


end

CheckObj(game.Workspace:FindFirstChild("Part"))

Any help is appreciated

function HasChildren(Object)
    return Object:IsA("BasePart") and #Object:GetChildren() ~= 0
end

this should tell you if the part has children or not

1 Like