Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
svjatik4 -13
4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
Let me know how it goes. DevMaster333 215 — 4y
0
It didn't work with Surface GUI. svjatik4 -13 — 4y
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. DevMaster333 215 — 4y
0
Thank. It's work svjatik4 -13 — 4y
0
You're welcome :) DevMaster333 215 — 4y
Ad
Log in to vote
0
Answered by
svjatik4 -13
4 years ago

It didn't work with Surface GUI.

Answer this question