Small DockWidgetUI Help

Hello there! I am trying to make a small plugin that just modifies a couple things, but I want it to be easily usuable and have it to be able to select something(kind of how 3d text plugins select things)

Have them select an object(special object name inside of it to check):

Have them set a value for something:

(I was planning to just have 1 number string 0-9 and then a text button to update it)

I have seen some tutorials but those haven’t helped. (While this isn’t recruitment if you want me to hire/pay you for this I would be happy to go along with that)

Thanks and have a nice day!

-F1sxher

You can use game.Selection:Get() to get the current selection as a table of Instances. You can use game.Selection.Changed to call a function every time the selection changes.

I know this ain’t helpful but that looks amazing and it looks like it’ll be really helpful.

I’m still a bit confused could you elaborate more?

I’m sorry, I misread your original post and was distracted by the “selecting” stuff.

Are you asking how to manage the different states of the plugin? I usually use the Maid library but for a relatively simple plugin like this you can just use a function to represent each state. I like to define a function for entering each state, and inside each “enter” function, a “leave” function / closure is defined that cleans up old connections and such. This cleanup function can be returned from each enter function so that code outside the different states can keep track of which state is active and potentially force a state to leave early. Or you can just not return the “leave” functions and have each state have complete control over when it transitions to another state.

Here’s an example of how that could look in code:


local InputS = game:GetService("UserInputService")

local toolbar = plugin:CreateToolbar("Test")
local toolbar_button = toolbar:CreateButton("Test", "", "", "")

function enter_idle()
	print("idle")
	local leave_idle
	local toolbar_button_click_c

	toolbar_button_click_c = toolbar_button.Click:Connect(function()
		leave_idle()
		enter_clicking()
	end)

	function leave_idle()
		leave_idle = function() warn("Already left idle state") end
		toolbar_button_click_c:Disconnect()
	end

	return function()
		leave_idle()
	end
end

function enter_clicking()
	print("clicking")
	local leave_clicking
	local toolbar_button_click_c
	local input_began_c

	toolbar_button_click_c = toolbar_button.Click:Connect(function()
		leave_clicking()
		enter_idle()
	end)
	
	input_began_c = InputS.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			leave_clicking()
			enter_editing()
		end
	end)

	function leave_clicking()
		leave_clicking = function() warn("Already left clicking state") end
		toolbar_button_click_c:Disconnect()
		input_began_c:Disconnect()
	end

	return function()
		leave_clicking()
	end
end

function enter_editing()
	print("editing")
	local leave_editing
	
	--Find the clicked 3d text or create a new one where the mouse is pointing
	local target_3d_text = find_target_3d_text() --TODO: implement
	if not target_3d_text then
		target_3d_text = create_3d_text_at_mouse() --TODO: implement
	end
	
	--TODO: Setup the eiditing connections and GUI
	
	function leave_editing()
		leave_editing = function() warn("Already left editing state") end
		--TODO: Cleanup the editing connections and GUI
		
		enter_idle()
	end
	
	return function()
		leave_editing()
	end
end

enter_idle()

If you save that as a local plugin it should create a toolbar button that transitions to the “clicking state”, and clicking in the 3d view should transition it to the “editing state”. Clicking the toolbar button again goes back to the “idle state”, i.e. “cancels” the operation.

You’ll have to implement the actual editing too. Let me know if you need help with that.

Thank you! I will try that a little bit but my main focus was to 1. have it so when you click the button it opens/closes a plugin gui

https://gyazo.com/4228dbdd4d8dfadbcd72050e5f51b820

and also have said gui be customized to be able to select something kind of how this plugin works:

https://gyazo.com/fd8136a7ccfb2b1c20a776b7a9d1496a

and then a few fields: a basic description of what it does, 3 fields to edit numbers 0-9 and then a button to apply changes.

Image of what im trying to edit:

1 Like

I would use SelectionService instead of game.Selection, better practice.

1 Like