I need help creating a plugin button

local toolbar = plugin:CreateToolbar("Studio Date")

local button = toolbar:CreateButton("Studio Date Widget", "rbxassetid://10861475043")

button.ClickableWhenViewportHidden = true

local function click()
	local widget = plugin:CreateDockWidgetPluginGui("Studio Date")
	widget.Title = "Studio Date"
	local Label = Instance.new("TextLabel")
	Label.BorderSizePixel = 0
	Label.TextSize = 20
	Label.TextColor3 = Color3.new(0.243137, 0.243137, 0.243137)
	Label.AnchorPoint = Vector2.new(0.5,0.5)
	Label.Size = UDim2.new(1,0,1,0)
	Label.Position = UDim2.new(0.5,0,0.5,0)
	Label.SizeConstraint = Enum.SizeConstraint.RelativeYY
	Label.Parent = widget
	while true do
		wait(60)
		Label.Text = "Studio Date: Year: "..os.date("%Y")..", Weekday: "..os.date("%A")..", Month: "..os.date("%B")..", Date and time: "..os.date("%c")..", Timezone: "..os.date("%Z")
	end
end
button.Click:Connect(click)

Hi, I need help to create a plugin button that displays a widget where os.date functions are written but the button does not appear, could you help me? Thank you.

2 Likes

CreateButton at minimum wants 3 parameters, an ID for the button, a tooltip text to display when you hover over the button and the image id to use for the button. Maybe it could be because you forgot to give it a hover/tooltip text?

now the button appears but the widget does not open

Could it be because you didn’t supply a DockWidgetPluginGuiInfo when creating it?

Try looking through the docs for Creating a dock widget and see if maybe that’s what the issue was
https://developer.roblox.com/en-us/api-reference/function/Plugin/CreateDockWidgetPluginGui

That or you need set the Enabled property for the widget, though not sure if that would cause any other issues

1 Like

Thanks a lot, now it works but there is still a very small problem, the output says that the plugin cannot create more than one PluginGui with the id “Studio Date”

You can’t have more than one widget with the same id, I think in your case what you’d do is create the widget outside of the click function, including the creation of the Label, make sure it starts disabled. Then when you press the button, it enables the widget and shows you the studio date, though I think it may be best to show an updated date on click rather than with an infinite loop since you’d be unable to stop it unless you reload studio unless there’s a condition it can listen to

1 Like