Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Surface GUI script not responding to buttonclicks?

Please help! I am making a surface GUI textbutton, and for some reason, the code is not working/responding to mouse clicks. Here is my code:

local button = script.Parent
local function onButtonActivated()
	print("gui authenticated")
end

button.Activated:Connect(onButtonActivated)

4 comments

0

try button.MouseButton1Click:Connect(onButtonActivated) ?

0

But its not activated its for tools. Try using MouseButton1Click instead.

0

none of this works. it just does not respond. i do not know why.

0

Nevermind(i was being dumb) i fixed it! Thanks' for the help!

2 answers

✓ Accepted answer

The reason is because you must have the Surface gui in the playerGui and have the adornee set to the part that you want the surface gui to be on. I believe it is safe to assume that you have the SurfaceGui in the part itself.

What you want to do is make sure the SurfaceGui parent is set to the player's playerGui. Like shown here (The starterGui, where it will end up in the playerGui)

Then, in your script. make sure the SurfaceGui's Adornee. Like shown here is set to the part that you want the surface gui to be shown on.

So you'll want your final code to look something like this:

local screenGui = script.Parent    -- or however you have this set lol
local button = screenGui.TextButton
local function OnButtonActivated()
	print("Gui Authenticated!")
end

screenGui.Adornee = workspace.Part

button.Activated:Connect(OnButtonActivated)

Hope this helps :)

1 comment

image link:

local guithing = script.parent.parent
local button = guithing.TextButton
button.MouseButton1Click:Connect(function()
	print("yeet")
end)

guithing.Adornee = workspace.tvscreencpp

This discussion is preserved as it was. New answers, comments, and votes are closed.