SurfaceGui Button is not working (Solved)

So while i was making my game, I came across a unpleasant problem.
The problem is script textbutton.mousebutton1click is not working i put the SurfaceGui to PlayerGui with setting Adornee at part and its not working either.
Is there anyone who can helps me?

1 Like

Hey man!

May I ask, are you getting any errors?

Could you also share some related code snippets too please? I’d love to try and help! :camel:

I notice your cursor isn’t changing to the clicky-hand in the screenshot you shared… are you sure the TextButton has the highest ZIndex of all the UI elements on the SurfaceGUI?

i recreated everything and ITS TRUE its not working maybe add a part and a CLICK DETECTOR on a invisible part above the gui so you could recreate it and when clicked you run the event

if this is what you want solution me ;D"

yeah when clicking surface gui buttons it doesnt go to the clicky hand ;P"

can you give a file of the gui so i can debug it?

local SurfaceGui = script.Parent

for i = 0, 8 do
local button = SurfaceGui:WaitForChild(“FloorPad”):FindFirstChild(“Floor”..i..“Button”)
print(“Found:”, button)
if button and button:IsA(“TextButton”) then
button.MouseButton1Up:Connect(function()
print(“works”, i)
end)
end
end

Thats the script and its not showing any errors in output
I tried as well this:
script.Parent.FloorPad.Floor0Button.MouseButton1Click:Connect(function()
print(“works”)
end)
And its not printing any massages.

1 Like

SurfaceGui.rbxm (14.9 KB)
Sure, here it is.

it seems to be working perfectly fine for me
the only suggestion i can make it setting the canvas size to {0,0,0,0} and AutomaticCanvasSize to Y

Strange when i open a new baseplate it suddenly works…

Strange that it works in a new baseplate, and I’m not too sure why!

However, may I recommend doing this instead? It may work more consistently possibly?

local SurfaceGui = script.Parent

for i,button in SurfaceGui:GetDescendants() do
	if button:IsA('TextButton') then
		button.MouseButton1Click:Connect(function()
			--codehere
		end)
	end
end

Otherwise I’d recommend checking the MaxDistance property of the SurfaceGui and ensuring it’s high enough.

Hope this helps a bit! :camel:

MaxDistance is set to 1000, is it good? Couse its still not working. :frowning:

maybe try button.Activated ? Also wouldn’t a click detector work if you add transparent parts that takes the form?

You see i want to use scrolling frame where i can scroll through levels/floors couse there gonna be like 50 of them.

Is there anything blocking the buttons in the original? A part or anything like that?

Definitely Adornee is setup correctly?

For sure something is blocking MouseButton1Click couse all properties are selected just the same
where the event works.
Comparison

Alright, we were actually somewhere :slight_smile:


After Removing every object in the clone of my game, script works but still
I cant figure out whats blocking MouseButton1Click event.
For sure it could be script or module beacuse.
Im not assume model or gui can cause such thing.

Hey, try Activated instead of MouseButton1Click.

If you think a 2d gui is interfering with the 3d one, you can try print(PlayerGui:GetGuiObjectsAtPosition(UserInputService:GetMouseLocation())) on UIS.InputBegan.

Thanks man for guiding me onto the right path because this is a problem:

CAS:BindAction("Grab", Grab, false, Enum.UserInputType.MouseButton1)

I have to change my grab script.