Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not a valid member of DataModel?

Asked by
B_Iu 31
6 years ago

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

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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
0
Thank you! B_Iu 31 — 6y
Ad

Answer this question