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.