Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by
Raccoonyz 893 Donator Moderation Voter
8 months ago

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)
0
What do you mean with ":Get()" on line 07? And what is "Selection"? Spjureeedd 279 — 8mo
0
it's getting selection Raccoonyz 893 — 8mo
0
Okay wait, I'll read up Spjureeedd 279 — 8mo
0
Okay I've read. I don't think you should do ":GetDescendants()". Just do it directly "print(#model)" Spjureeedd 279 — 8mo
View all comments (2 more)
0
nono won't work Raccoonyz 893 — 8mo
0
Try copy all code that is inside the function and use it in the Command Box, Selection doesn't work in scripts Spjureeedd 279 — 8mo

1 answer

Log in to vote
0
Answered by 8 months ago
Edited 8 months ago

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

0
Thank you so much Raccoonyz 893 — 8mo
Ad

Answer this question