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

Not a valid member of DataModel?

Hi. I'm making a small command system, and it's going pretty well. I've stumbled upon an issue where I'm trying to print the number of children in a certain directory. It works well for simple things like workspace, or Lighting, until you get to things like workspace.B_Iu. The script is below:

function Run(ChatService)
	
	ChatService:RegisterProcessCommandsFunction("prt", function(speakerName, message, channel)
		if speakerName == "B_Iu" then
			if string.sub(message, 1, 5) == ";prtc" then
				local dir = string.sub(message, 7)
				local val = #game[""..dir..""]:GetChildren()
				print("There are currently ".. val .." objects in the ".. dir)
			end
		end
		return false
	end)
end
return Run

It returns an error of "DoProcessCommands Function 'prt' failed for reason: workspace.B_Iu is not a valid member of DataModel." Not sure how I can get past this.

1 answer

✓ Accepted answer

That's because the [] brackets evaluate the string. So doing game["Workspace"] it's equal to game.Workspace, but if you do game["workspace.B_Iu"] then it looks for an instance named literally workspace.B_Iu under the DataModel.

Try doing something like this:

function Run(ChatService)

    ChatService:RegisterProcessCommandsFunction("prt", function(speakerName, message, channel)
        if speakerName == "B_Iu" then
            if string.sub(message, 1, 5) == ";prtc" then
                local dir = string.sub(message, 7)
                local val = #loadstring([[return game.]] .. dir .. [[:GetChildren()]])()
                print("There are currently ".. val .." objects in the ".. dir)
            end
        end
        return false
    end)
end
return Run

1 comment

0

Thank you!

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