I have put a surfacegui into a part in workspace by setting the surfacegui’s adornee to the part, however the textbutton (.Activated) does not work all the time. I am unsure whether this is a scripting error or a bug since the button works sometimes.
LocalScript:
local TextButton = script.Parent:WaitForChild('TextButton')
TextButton.Activated:Connect(function()
print('button pressed')
end)
The surfacegui is set to a part in workspace, as seen in the adornee. It is in startergui so that I can get the player from the textbutton being activated.
Instead of detecting when the button is clicked, you can try detecting when the part that the SurfaceGui is adorneed to is clicked.
local part = workspace.Part -- Change this to reference your part
local ClickDetector = part.ClickDetector
ClickDetector.MouseClick:Connect(function()
print('button pressed')
end)
Make sure to place a click detector inside of the part that you want to be clicked.
I used this in the past but it would be unrealistic for what I am trying to do since the screen would be changing as well as the location of the button.
Try using this edit to your script with print statements, and let me know what gets printed in the output.
local TextButton = script.Parent -- Change this to your text button name/path
local AdorneePart = workspace.Part -- Change this to your part name/path
if AdorneePart then
-- Check if the TextButton is adorning the specified part
local adorn = AdorneePart:FindFirstChildOfClass("TextLabel")
if adorn and adorn:IsA("TextLabel") and adorn == TextButton then
print('AdorneePart found')
TextButton.Activated:Connect(function()
print('Button pressed')
end)
else
warn("The TextButton is not adorning the specified part.")
end
else
warn("AdorneePart not found.")
end
I think I found the problem: Set the AlwaysOnTop property of the SurfaceGui to be true, then change the face side of the SurfaceGui to be what you want, and the problem is fixed (it worked for me, anyway). You can keep your original script, and it will work.