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)
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)