Why won't buttons work on SurfaceGuis?

Hello!

Do you know why TextButtons do not work in that case?
They don’t change colors on hover (like this)image

They don’t react to scripts.
image
It is on a SurfaceGui.

Here’s my code:

function onClick()
	print("oof")
end

for i, v in pairs(script.Parent:GetChildren()) do -- Loops in the SurfaceGui
	if v:IsA("TextButton") then -- Checks if it's a TextButton
		v.MouseButton1Click:Connect(onClick) -- Activates
	end
end

script.Parent.A.MouseButton1Click:Connect(onClick) -- Attempt to check if it was the for loop above causing the issue, didn't fix it.

Any ways to fix this?

Thanks in advance,
Mehdi

1 Like

Could we see the scripts you used if that might be the problem?

Sure. Here is my code:

function onClick()
	print("oof")
end

for i, v in pairs(script.Parent:GetChildren()) do -- Loops in the SurfaceGui
	if v:IsA("TextButton") then -- Checks if it's a TextButton
		v.MouseButton1Click:Connect(onClick) -- Activates
	end
end

script.Parent.A.MouseButton1Click:Connect(onClick) -- Attempt to check if it was the for loop above causing the issue, didn't fix it.

The SurfaceGui has to be a parent (or descendant) of the player’s PlayerGui for it to be functional and react to player inputs. You will have to put the gui in StarterGui and change the gui’s Adornee property for it to be visible on the part

Weird, because my second SurfaceGui on the same parts works.

Tried setting the “Adornee” parameter to the “screen” part: It works! Thanks, marking your answer as the answer.