Is this code correct?

I’m making a utility and I want to know if this code is correct or can be improved.

function ServerUtilities:GetChunkNPCs(ChunkID)
	local Chunk = ChunksFolder[ChunkID]
	for i, ChunkData in pairs(Chunk:GetChildren()) do
		local CurrentAsset = ChunkData:IsA("Model")
		if CurrentAsset.Name:Match("NPC") then
			return {CurrentAsset}
		end
	end
end

Nope, it’s wrong…

CurrentAsset is the return of the IsA method which is a boolean but then you used .Name which isn’t a valid item of a boolean, did you mean FindFirstChild?

3 Likes

to add onto what @msix29 said, if you’re trying to find a model, you can do this:

local CurrentAsset = ChunkData:FindFirstChildOfClass("Model")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.