"Attempt to call a nil value" error while trying to test my plugin

I am trying to make this UI Transformer plugin, which copies the properties of the UI element selected and transforms them into code. The code is put in a temporary script as a child of the selected element so the users can copy the code from there. However, when I run the code, it tells me “Attempt to call a nil value.” Now this is definitely because of my bad coding skills. Another thing I must point out is that I looked up how to do multiple lines on the dev forum, and that’s all I did. Here is the code:

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

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

-- Add a toolbar button named "Create Empty Script"
local transformButton = toolbar:CreateButton("Transform UI", "Transforms the currently highlighted UI element in the Explorer into code", "rbxassetid://4728126418")

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

local function onTransformButtonClicked()
	local selectedObjects = Selection:Get()
	local parent = nil
	if #selectedObjects == 1 then
		parent = selectedObjects[1]
		
		if parent.ClassName == "TextButton" then
			local newScript = Instance.new("Script")
			newScript.Source = [[local button = Instance.new("TextButton")
			button.Name == ]..parent.Name..[
			button.Parent = ]..parent]]
			newScript.Parent = parent
			ChangeHistoryService:SetWaypoint("Transformed TextButton into code")
		end
	end
end

transformButton.Click:Connect(onTransformButtonClicked())

The comments are not 100 percent accurate because I copied the code from the developer hub and modified it.

1 Like

What line does the error say? chars chars chars

Oh yeah also whenever I save as a local plugin it says “Attempt to connect failed: Passed value is not a function” at line 30

1 Like

Try

transformButton.Click:Connect(onTransformButtonClicked)

Aaaaaah, number one mistake. The output wasn’t what I expected, but I’ll work on it later. I’ll take it from here. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.