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

How to write a script so that in the surface GUI it works when the button is pressed?

I wrote a script to make the other part transparent by clicking on part. But when I added a GUI to the part surface and added a button and added a script it didn't work. And I need help to make the script I wrote work when I press a button with Surface GUI

function TEST ()
 
 game.Workspace.Part.Transparency = 1

end
 
game.Workspace.partt.ClickDetector.MouseClick:Connect(TEST)

2 answers

✓ Accepted answer

There is an error in "partt". What you should do first is create a variable to define the part. Then define the click detector and finally make the connection.

Here's how:

local part = game.Workspace:FindFirstChild("Part")
local clickDetector = part:FindFirstChild("ClickDetector")

local function Test()
part.Transparency = 1
end

-- Create the connection
clickDetector.MouseClick:Connect(Test)

If it's a GUI then you should use a TextButton. Insert the TextButton under the ScreenGUI/SurfaceGUI then insert the Script under the ScreenGui/SurfaceGui. Then inside the script you would put this:

local part = game.Workspace:FindFirstChild("Part")
local textButton = script.Parent

local function Test()
part.Transparency = 1
end

-- Create the connection
textButton.MouseButton1Click:Connect(Test)

5 comments

0

Let me know how it goes.

0

It didn't work with Surface GUI.

0

If it's a surface GUI then you shouldn't use a click detector but rather a TextButton or an ImageButton. Check my edit and let me know how it goes.

0

Thank. It's work

0

You're welcome :)

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