I cant modify a selected object (plugin creation)

Hi, I am having problems with my plugin, I can’t figure out how to do anything with the parts i have selected on my plugin, here is a section of the code:

	--updateconfig
spawn(function()
while  wait(1) do
 current = selection:Get()
		for i, v in ipairs(current) do
	 	local convertedString = tostring(current[i])
	 	SelectedPart.Text = "Part: ".. convertedString
		end
	end
end)
--funcs
RotateAdd.MouseButton1Down:Connect(function()
	current:Destroy()
end)

Everything here but current:Destroy() works perfectly, i know that current is a array but I don’t know how I should get the object selected instead of a string array.

Any help would be extremely appreciated, thanks.

note: selection is from local selection = game:GetService("Selection")

current is a table of Instance. Destroy is a method of a single instance. You can only call Destroy on an instance – not a table. You will need to iterate through every instance in the table and destroy each one.

2 Likes

Yeah i knew that after i revised the script carefully, but how can I do that?

Just found out the awnser!
I had to make another variable which unpacks current and then can be destroyed
also i was wrong about selection being a string table, it is really an instance table:
local ctable = unpack(current)

This will only get the first unpacked item. If you’re selecting multiple things, you would have to loop through current and destroy each one.

1 Like

You could also catch the returns in an array, which is probably what OP meant to do.

local ctable = {unpack(current)}

I was really looking to select only one object, thanks tho