Not Able To Reference An Event In TextButton Parented Under Widget

So, I have a TextButton taht is created trough a script, and a script taht is patented under the button, but when I try doing:

button.MouseButton1Down

It trows an error for some reason, if you need the full script just ask

You should always support the whole script, so please, send it

1 Like

Okay:
Script that creates the button (there’s some variables taht are to create the plugin, I don’t think you need them):

local weldButton = Instance.new(“TextButton”);
weldButton.Text = “Create Weld”;
weldButton.Size = UDim2.new(1,0,1,0);
weldButton.Visible = true
weldButton.Parent = widget

local weldScript = game:GetService(“ServerScriptServuce).WeldPlugin.WeldScript
weldScript.Parent = weldButton

That’s what creates the button and reparents the weldScript

The script taht errors:

local selection = game:GetService(“Selection”)

local function onClick()
local selected = selection:Get();
if #selected == 1 then
print(“Selected one object”)
else
warn(“Select only one main part!”)
end
end

button.MouseButton1Down:Connect(onClick) --here it errors

Error:
‘MouseButton1Down is not a valid member of Folder “user_WeldPlugin.rbxmx.WeldPlugin”

I am not solid with how Plugins work but this shows that you are trying to Click a folder?

button.MouseButton1Down:Connect(onClick) --here it errors

to

weldButton.MouseButton1Down:Connect(onClick) 
-- Make sure to define weldButton if this all isnt in one script

This is on a LocalScript that is parented under the weldButton, meaning taht script.Parent is the button

I’m sure taht it’s changing parent as I see that it disappears from the folder in which it’s in by default

script.Parent.MouseButton1Down:Connect(onClick)

That doesnt work?? Let me find a doc for you then

I’ll try that ASAP

Still trows the same error

Apparently this is how you create a new button

-- Add a toolbar button named "Create Empty Script"
local newScriptButton = toolbar:CreateButton("Create Empty Script", "Create an empty script", "rbxassetid://4458901886")

The button needs to be a TextButton, the one in the toolbar already existss

Yeah then just try what I sent, sorry about that

Welp Dede heres your solution:

button.InputBegan:Connect(function(i)
if i.UserInputType == Enum.UserInputType.MouseButton1 then
-- do sum goofy ah stuff
end
end)

yes it was tested

1 Like

It’s not working for some reason, I used your code but it’s not working, it’s still printing the same error but with InputBegan, I’m trying to create it from script now and I’ll tell you do it works

Edit: still doesn’t work

ok so have you activated the mouse?
type plugin:Activate(true) in the main plugin script and use

plugin.Deactivated:Connect(function()
plugin:Activate(true)
end)

if you want it to like always be active (the top code piece is optional)

The error is literal, you’re trying to use the connection on a folder, are you sure you’re referencing the correct textbutton?

Creating the UI from start and using it as the code goes on is sometimes a better idea, I don’t know if you managed to stop more-than-one buttons being created.

Yes I’m sure, the WeldScript when I try to edit it while it’s patented to the button gives me MouseButton1Down and only-buttons options

@SomeFedoraGuy how would I put the GUI in the widget?

Are you using Roblox Studio’s widgets or creating your own UI?

I’m using Studio’s ones