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

What's the issue with my script? (attempt to call a nil value)

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)

6 comments

0

What do you mean with ":Get()" on line 07? And what is "Selection"?

0

it's getting selection

0

Okay wait, I'll read up

0

Okay I've read. I don't think you should do ":GetDescendants()". Just do it directly "print(#model)"

0

nono won't work

0

Try copy all code that is inside the function and use it in the Command Box, Selection doesn't work in scripts

1 answer

✓ Accepted answer

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].

1 comment

0

Thank you so much

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