Problem with editing source code within a plugin

I’m trying to make a button for my plugin that when you click it, it makes a script in the workspace that has all the colours in the palette. If you could help me, it would be greatly appreciated and I don’t want all my writing and time going to waste ;-;

Script for the button:

toolbarColourListButton.Click:Connect(function()
	local colourList = Instance.new("Script", workspace)
	colourList.Name = "Colour List"
	colourList.Source = {
		""
	}
end)

What I want to put inside the text:

-- Written by xCynacol 2020

-- !NOTICE! --
-- Colours soon to be in alphabetical order.

-- Green Colours --

--[[
	Lime green
	Grime
	Forest green
	Dark green
	Slime green
	Earth green
	Camo
	Parsley green
	Shamrock
	Sea green
	Bright green
	Bright bluish green
	Artichoke
	Moss
	Sand green
	Br. yellowish green
	Sage green
	Pastel green
	Medium green
	Mint
	Olivine
	Laurel green
	Pastel blue-green
]]

-- Yellow Colours --

--[[
	New Yeller
	Gold
	Br. yellowish green
	Olive
	Deep orange
	Pastel yellow
	Cool yellow
	Buttermilk
]]

-- Blue Colours --

--[[
	Dark blue
	Navy blue
	Bright bluish green
	Deep blue
	Teal
	Toothpaste
	Pastel blue-green
	Steel blue
	Lapis
	Storm blue
	Pastel Blue
	Light blue
	Baby blue
	Cyan
	Pastel light blue
	Cadet blue
	Medium blue
	Electric blue
	Bright blue
]]

-- Pink/Purple Colours --

--[[
	Magenta
	Hot pink
	Pink
	Dark indigo
	Mulberry
	Eggplant
	Royal purple
	Lavender
	Bright violet
	Plum
	Lilac
	Alder
	Pastel violet
	Carnation pink
]]

-- Red Colours --

--[[
	Crimson
	Maroon
	Bright red
	Really red
	Persimmon
]]

-- Monochromatic (grey, black, white) Colours --

--[[
	Really black
	Black
	Lily white
	Institutional white
	Dark stone grey
	Fossil
	Medium stone grey
	Smoky grey
	Hurricane grey
	Oyster
	Cloudy grey
	Quill grey
	Mid grey
	Ghost grey
	Pearl
	Fog
	Light stone grey
	White
	Flint
]]

-- Brown/Peach Colours --

--[[
	Cocoa
	Rust
	Burgundy
	Brown
	Dark orange
	Burnt Sienna
	Dusty Rose
	Terra Cotta
	Tawny
	Salmon
	Pastel orange
	Medium red
	Light orange
	Pastel brown
	Seashell
	Nougat
	Brick yellow
	Copper
	Linen
	Dark taupe
	Neon orange
	CGA brown
	Reddish brown
	Pine Cone
	Dirt brown
	Bright orange
	Wheat
	Br. yellowish orange
	Cashmere
	Khaki
	Cork
	Burlap
	Beige
	Fawn brown
	Sand red
	Bronze
]]

(The name of the plugin is Workspace Manager, and I got a warning for putting an image for the little icon of the Workspace in studio as the icon of the plugin)

Long strings can be created using the double square bracket notation

toolbarColourListButton.Click:Connect( function ()
	local colourList = Instance.new( "Script" )
	colourList.Name = "Colour List"
    colourList.Source = [[-- Written by xCynacol 2020

-- !NOTICE! --
-- Colours soon to be in alphabetical order.

-- Green Colours --

--[[
	Lime green
	Grime
	Forest green
	Dark green
	Slime green
	Earth green
	Camo
	Parsley green
.......etc
]]
    ]]
    colourList.Parent = workspace
end )

And to answer your second post, yes you will get warned if you in any way imitate or pretend to be built-in tools and services. You’re a third party plugin - use your own icon rather than causing confusion with a trusted icon.

Ok, thanks for the advice. I’ll try that out.

My script is:

toolbarColourListButton.Click:Connect(function()
	local colourList = Instance.new("Script", workspace)
	colourList.Name = "Colour List"
	colourList.Source = [[
		
-- Written by xCynacol 2020

-- !NOTICE! --
-- Colours soon to be in alphabetical order.

-- Green Colours --

--[[
	Lime green
	Grime
	Forest green
	Dark green
	Slime green
	Earth green
	Camo
	Parsley green
	Shamrock
	Sea green
	Bright green
	Bright bluish green
	Artichoke
	Moss
	Sand green
	Br. yellowish green
	Sage green
	Pastel green
	Medium green
	Mint
	Olivine
	Laurel green
	Pastel blue-green
]]
	
	-- Yellow Colours --
	
--[[
	New Yeller
	Gold
	Br. yellowish green
	Olive
	Deep orange
	Pastel yellow
	Cool yellow
	Buttermilk
]]
	
	-- Blue Colours --
	
--[[
	Dark blue
	Navy blue
	Bright bluish green
	Deep blue
	Teal
	Toothpaste
	Pastel blue-green
	Steel blue
	Lapis
	Storm blue
	Pastel Blue
	Light blue
	Baby blue
	Cyan
	Pastel light blue
	Cadet blue
	Medium blue
	Electric blue
	Bright blue
]]
	
	-- Pink/Purple Colours --
	
--[[
	Magenta
	Hot pink
	Pink
	Dark indigo
	Mulberry
	Eggplant
	Royal purple
	Lavender
	Bright violet
	Plum
	Lilac
	Alder
	Pastel violet
	Carnation pink
]]
	
	-- Red Colours --
	
--[[
	Crimson
	Maroon
	Bright red
	Really red
	Persimmon
]]
	
	-- Monochromatic (grey, black, white) Colours --
	
--[[
	Really black
	Black
	Lily white
	Institutional white
	Dark stone grey
	Fossil
	Medium stone grey
	Smoky grey
	Hurricane grey
	Oyster
	Cloudy grey
	Quill grey
	Mid grey
	Ghost grey
	Pearl
	Fog
	Light stone grey
	White
	Flint
]]
	
	-- Brown/Peach Colours --
	
--[[
	Cocoa
	Rust
	Burgundy
	Brown
	Dark orange
	Burnt Sienna
	Dusty Rose
	Terra Cotta
	Tawny
	Salmon
	Pastel orange
	Medium red
	Light orange
	Pastel brown
	Seashell
	Nougat
	Brick yellow
	Copper
	Linen
	Dark taupe
	Neon orange
	CGA brown
	Reddish brown
	Pine Cone
	Dirt brown
	Bright orange
	Wheat
	Br. yellowish orange
	Cashmere
	Khaki
	Cork
	Burlap
	Beige
	Fawn brown
	Sand red
	Bronze
]]
	]]
end)

And the error I got was:
Expected identifier when parsing expression, got ‘]’

Can you paste the whole error. It should have a line number with it.

I suspect the long comments inside the source might be causing issues.

no like, what i mean by error is like the thing at the bottom of the script

Okay, it’ll be due to the long comments inside.

In your source, replace all of the [[ and ]] comment opening and closing lines with \[\[ and \]\].

Then, before writing to the source of the script, do a string.gsub to replace them all.

Here’s a simplified example:

local s = [[
    This is some code here
    -- This is a comment
    --\[\[
    This is a multiline comment
    \]\]
    And here is some code
]]

s = s:gsub( '\\[', '[' )
s = s:gsub( '\\]', ']' )

yourNewScript.Source = s

like this?

--VARIABLES--

local colourListText = [[

-- Written by xCynacol 2020

-- !NOTICE! --

-- Colours soon to be in alphabetical order.

-- Green Colours --

--\[\[

Lime green

Grime

Forest green

Dark green

Slime green

Earth green

Camo

Parsley green

Shamrock

Sea green

Bright green

Bright bluish green

Artichoke

Moss

Sand green

Br. yellowish green

Sage green

Pastel green

Medium green

Mint

Olivine

Laurel green

Pastel blue-green

\]\]

-- Yellow Colours --

--\[\[

New Yeller

Gold

Br. yellowish green

Olive

Deep orange

Pastel yellow

Cool yellow

Buttermilk

\]\]

-- Blue Colours --

--\[\[

Dark blue

Navy blue

Bright bluish green

Deep blue

Teal

Toothpaste

Pastel blue-green

Steel blue

Lapis

Storm blue

Pastel Blue

Light blue

Baby blue

Cyan

Pastel light blue

Cadet blue

Medium blue

Electric blue

Bright blue

\]\]

-- Pink/Purple Colours --

--\[\[

Magenta

Hot pink

Pink

Dark indigo

Mulberry

Eggplant

Royal purple

Lavender

Bright violet

Plum

Lilac

Alder

Pastel violet

Carnation pink

\]\]

-- Red Colours --

--\[\[

Crimson

Maroon

Bright red

Really red

Persimmon

\]\]

-- Monochromatic (grey, black, white) Colours --

--\[\[

Really black

Black

Lily white

Institutional white

Dark stone grey

Fossil

Medium stone grey

Smoky grey

Hurricane grey

Oyster

Cloudy grey

Quill grey

Mid grey

Ghost grey

Pearl

Fog

Light stone grey

White

Flint

\]\]

-- Brown/Peach Colours --

--\[\[

Cocoa

Rust

Burgundy

Brown

Dark orange

Burnt Sienna

Dusty Rose

Terra Cotta

Tawny

Salmon

Pastel orange

Medium red

Light orange

Pastel brown

Seashell

Nougat

Brick yellow

Copper

Linen

Dark taupe

Neon orange

CGA brown

Reddish brown

Pine Cone

Dirt brown

Bright orange

Wheat

Br. yellowish orange

Cashmere

Khaki

Cork

Burlap

Beige

Fawn brown

Sand red

Bronze

\]\]

]]

colourListText = colourListText:gsub('\\[', '[')

colourListText = colourListText:gsub('\\]', ']')

-- Variable Instances

local toolbar = plugin:CreateToolbar("Workspace Manager")

local toolbarNewPartButton = toolbar:CreateButton("New Part", "Creates a new part in the Workspace (you can put it where you want)", "rbxassetid://13951636")

local toolbarColourListButton = toolbar:CreateButton("Colour List", "Creates a list of all colours in the Workspace", "rbxassetid://15205694")

toolbarNewPartButton.Click:Connect(function()

local newPart = Instance.new("Part", workspace)

end)

toolbarColourListButton.Click:Connect(function()

local colourList = Instance.new("Script", workspace)

colourList.Name = "Colour List"

colourList.Source = colourListText

end)

Yeah exactly. The backslash escapes the square brackets to prevent confusion with the start and end of the multiline string :slight_smile:

Give it a test and see how you get on.

ok ill try it out if it dosnt work ill say

wait wait i think it might work

nope it dosnt work but the buttons and the toolbar comes up

You can have [[ within a multiline string but not ]]. Any [['s after are just treated as the contents of the string, but ]] closes off the string. You can have an arbitrary amount of ='s in between the opening and closing brackets as long as they match.

colourList.Source = [==[-- Written by xCynacol 2020

-- !NOTICE! --
-- Colours soon to be in alphabetical order.

-- Green Colours --

--[[
	Lime green
	Grime
	Forest green
	Dark green
	Slime green
	Earth green
	Camo
	Parsley green
.......etc
]]
]==]

Notice the 2 equal signs I put in between the brackets that enclose the string. The amount can be arbitrary however the amount must be the same for the opening and closing brackets. You could do this to the comments instead as well.

(cc @BanTech)

3 Likes

Let me try this out. I’ll get back to you saying if it works or doesn’t work.

YES! Thank you so much, it works!