:GetDescendants() Not Working

Hello developers,

I was recently working on a plugin, that I wanted to rework. I made a modulescript with functions, and one of the functions uses :GetDescendants(), however it’s not working how it’s supposed to.

Function Code:

function module.CheckIfObjectExists(objectname : string)
	
	for i, desc in pairs(game:GetDescendants()) do
		
		if desc.Name == objectname then
			
			return true
			
		end
		
	end
	
	return false
	
end

Any Help is greatly Appreciated,
OceanTubez

function module.CheckIfObjectExists(objectname : string)
	for i, desc in pairs(game:GetDescendants()) do
		if desc.Name == objectname then
			return true
		else
			return false
		end
	end
end

But that code will simply just return false!

Because it will just check if the thing exists once, and if it doesn’t, it’ll just return false and close the function!

Ah, my bad. Try this, I doubt it will work but worth a try

local Exists = false

function module.CheckIfObjectExists(objectname : string)
	for i, desc in pairs(game:GetDescendants()) do
		if desc.Name == objectname then
			Exists = true
		else
			Exists = false
		end
	end
return Exists
end

Issue fixed! It was simply a module function argument issue.