I have this plugin script right here. However, it doesn't work. What's my issue? It yields Script.lua:9: attempt to call a nil value
local toolbar = plugin:CreateToolbar("Number of Descendants") -- Add a toolbar button named "Create Empty Script" local newScriptButton = toolbar:CreateButton("Get Number of Descendants", "Gets the numbre of descendants", "rbxassetid://4458901886") local function onNewScriptButtonClicked() local model = game.Selection:Get() local descend = model:GetDescendants() local number = #descend print("number") end newScriptButton.Click:Connect(onNewScriptButtonClicked)
game.Selection:Get() gives you an array of objects, not just one object, since multiple objects can be selected simultaneously. Hence the model — if only the model is selected — will actually be game.Selection:Get()[1].