SurfaceGui Button Doesn't work

What happens:

Code:

script.Parent.MouseButton1Click:Connect(function()
local pg = game.Players.LocalPlayer.PlayerGui
local SG = Instance.new("ScreenGui",pg)
local FRM = Instance.new("Frame",SG)
end)

Hierarchy:

Screen Shot 2020-06-14 at 12.49.44 PM

What I want to happen:

Have the button in the SurfaceGui do something when it is clicked.

4 Likes

You could try using:
script.Parent.Activated because I don’t think MouseButton1Click works on surface guis

A LocalScript doesn’t run when it’s a descendant of the Workspace. To fix this, you can parent the SurfaceGui to the StarterGui and set the Adornee property to the part which should display the SurfaceGui.

27 Likes

This is what I did and I tried over a 50 times, I even tired to keep a seperate local script to the gui buttons, but they are not clickable, please help

local gui = game.ReplicatedStorage:WaitForChild("OrderTrainGui")

game.ReplicatedStorage.OrderTrainEvent.OnClientEvent:Connect(function(screenpart,guipart)
    screenpart:Destroy()
    local clone = gui:Clone()
    local gui1 = clone:FindFirstChild("1")
    local gui2 = clone:FindFirstChild("2")
    clone.Parent = script.Parent
    clone.Adornee = guipart
    gui1.Visible = true
    guipart.SurfaceGui.MainFrame:FindFirstChild("StartingFrame").Visible = false
end)

Replying two years later :interrobang: Wow

1 Like

Dude the event is not getting fired

script.Parent.Activated:Connect(function()
    print("bruhhh")
end)

script.Parent.MouseButton1Click:Connect(function()
    print("bruhhh")
end)

It does not print bruh or anything or any error, why it is not getting fired

you can register cilck event on the ScreenGui or LocalScript on the StartPlayer