Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why don't the buttons in the GUI in my plugin work?

Asked by 7 years ago

So, I've made a plugin that works fine. The GUI opens/closes. But the only problem I'm having is that the buttons in the GUI doesn't work.

Plugin script:

print("Part creator plugin loaded!") -- I was bored, so I decided to do something random

local toolbar = plugin:CreateToolbar("dragonmaster4111")
local button = toolbar:CreateButton(
    "Create Part",
    "Click anywhere to insert a part at your mouse position",
    "rbxassetid://430069553"
)

function InsertGUI()
    script.Parent.GUI:Clone().Parent = game.CoreGui
end
function RemoveGUI()
    game.CoreGui:FindFirstChild("GUI"):Destroy()
end
button.Click:connect(function()
    if not game.CoreGui:FindFirstChild("GUI") then
        InsertGUI()
    else
        RemoveGUI()
    end
end)

And, the script inside the button that doesn't work when you click it:

script.Parent.MouseButton1Click:connect(function()
    if script.Parent.Parent.Types.Visible  ~= true then
        script.Parent.Parent.Types.Visible = true
        script.Parent.Rotation = 180
    else
        script.Parent.Types.Visible = false
        script.Parent.Rotation = 0
    end
end)

Note: This plugin has everything in a folder. The GUI is premade. The script clones it into CoreGui when you click the button in it's toolbar.

1
Why a downvote? At least tell me what I need to change. Operation_Meme 890 — 7y

3 answers

Log in to vote
1
Answered by 4 years ago

Old question but it bothers me when the only reference to a problem I had, has no solution. I was able to resolve this issue by waiting for the GUI in core with:

game.CoreGui.ChildAdded:Connect(function(child)

-- need to use WaitForChild as descendants may not have replicated yet --local head = child:WaitForChild("Head") --guiLocation.ClickerWindow.Frame.TextButton.MouseButton1Click:Connect(insertClickEvent) end)

Ad
Log in to vote
0
Answered by 7 years ago

Example

Below is an example of how a plugin should be structured

print("Loading Block Identifier...")

-- Check if user has loaded plugin before
local hasLoaded = plugin:GetSetting("pluginHasLoaded")
if not hasLoaded then
    print("Welcome to the Block Identifier. To use this plugin, click on the button in the addon bar, then click on the object you want to inspect.")
    plugin:SetSetting("pluginHasLoaded", true)
end

-- Setup Toolbar
local toolbar = plugin:CreateToolbar("Block Identifier")

-- Setup button
local button = toolbar:CreateButton(
    "Button",
    "Press me",
    "http://www.roblox.com/asset/?id=145723965"
)
button.Click:connect(function()
    print("Plugin is now active")
    plugin:Activate(true) -- Neccessary to listen to mouse input
end)

-- Setup mouse
-- ADD THIS TO THE SCRIPT
local mouse = plugin:GetMouse()
mouse.Button1Down:connect(function() -- Binds function to left click
    local target = mouse.Target -- PUT WHAT EVER WAS IN YOUR LOCAL SCRIPT IN HERE
    if target then
        print("Target: " .. target.Name)
    end
    print("X: " .. mouse.X .. " Y: " .. mouse.Y)
end)

print("Finished Loading Block Identifier")

0
Yes, but that still doesn't fix my problem about the buttons. Operation_Meme 890 — 7y
Log in to vote
-1
Answered by 7 years ago

I believe event you used in line 1 of the script inside of the button should instead be MouseButton1Down: script.Parent.MouseButton1Down:connect(function()

0
Pretty sure MouseButton1Down and MouseButton1Click do the same thing. But I'll try anyway. Operation_Meme 890 — 7y

Answer this question