#Creating A Plugin: EmptyScriptAdder

1 messages · Page 1 of 1 (latest)

errant fog
#

I'm currently following Roblox Documentation here:
https://create.roblox.com/docs/studio/plugins

The script segment that they show as an example is here:

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")

-- Create a new toolbar section titled "Custom Script Tools"
local toolbar = plugin:CreateToolbar("Custom Script Tools")

-- Add a toolbar button named "Create Empty Script"
local newScriptButton = toolbar:CreateButton("Create Empty Script", "Create an empty script", "rbxassetid://14978048121")

-- Make button clickable even if 3D viewport is hidden
newScriptButton.ClickableWhenViewportHidden = true

local function onNewScriptButtonClicked()
    local selectedObjects = Selection:Get()
    local parent = game:GetService("ServerScriptService")
    if #selectedObjects > 0 then
        parent = selectedObjects[1]
    end

    local newScript = Instance.new("Script")
    newScript.Source = ""
    newScript.Parent = parent
    ChangeHistoryService:SetWaypoint("Added new empty script")
end

newScriptButton.Click:Connect(onNewScriptButtonClicked)```

The script above is what I am working with.

I'm not sure if it's possible, but I would like to select/click an object/instance in the explorer and having the selection become the parent for the script, instead of hard-coding the parent to 'ServerScriptService'.

Is this possible, and if so, how would I go about doing this? I've tried to research it though I have not come across anything.

Explains how to create, publish, and monetize extensions to Studio that add custom functionality.

unique nest
#

game:GetService("Selection") gets the selection service

#
local Selection = game:GetService("Selection")
local selectedInstances = Selection:Get()
errant fog
#

Yeah i'm looking at that now and I just realized 😳

errant fog
# unique nest Selection

Thank you for pointing that out to me, and I can pretty much just parent that right?

And if it's nil, check and spit out a warning and if not then good right?

unique nest
#

check for that and warn yes

errant fog
#

Oh alright thank you! Tables are = {} right? I've tried doing that before but I got an error, so could I get away with doing

if #selection = 0```

Instead of 

```Lua
if selection == {}
```?
unique nest
#

the second one wouldn't work actually

#

;compile

print({} == {})
gaunt lightBOT
#
Program Output
false

unique nest
#

tables exist as unique objects

errant fog
#

Okay yeah cause that never worked for me when I tried

unique nest
#

it would only be true if it's a reference to that specific table

errant fog
#

Ah I see

#

So then would this work?

if #selection = 0```
#

I've done that before with tables and it worked for what I was doing, though since this is for a plugin I wasn't sure if it would

unique nest
#

use the == operator

#

= is assignment

errant fog
unique nest
#

yeah

errant fog
#

Okay thank you HiLock!