My Script is broken! Please help me fix

Hello, my name is SuperPogr!
Here I will ask for your help to help me improve my script. So in this script I want to create an object that when clicked will display a UI that contains the question “Do you want to grab this thing?” and after that is the option Yes or no well this is where my problem is when pressing the yes or no button I try to hide the UI by using

--Script inside yes and no button

local Grab = game.StarterGui.ScreenGui.GrabGui --Local

script.Parent.MouseButton1Click:Connect(function() --ClickDetector Setting
	script.Parent.Visible = false --"No" button become invisible
	Grab.Visible = false --Ui suppose to be invisible
end)

The following is also a script in the part that will be pushed by the player and will bring out the UI.

local Part = game.Workspace.Part
local TextUI = game.Workspace.Part.BillboardGui.TextBoxUI
local Edge1 = game.Workspace.Edge.Edge1
local Edge2 = game.Workspace.Edge.Edge2
local Edge3 = game.Workspace.Edge.Edge3
local Edge4 = game.Workspace.Edge.Edge4
local Edge5 = game.Workspace.Edge.Edge5
local Edge6 = game.Workspace.Edge.Edge6
local Edge7 = game.Workspace.Edge.Edge7
local Edge8 = game.Workspace.Edge.Edge8
local Edge9 = game.Workspace.Edge.Edge9
local Edge10 = game.Workspace.Edge.Edge10
local Edge11 = game.Workspace.Edge.Edge11
local Edge12 = game.Workspace.Edge.Edge12


script.Parent.ClickDetector.MouseClick:Connect(function(player)
	player:WaitForChild("PlayerGui").ScreenGui.GrabGui.Visible = true --change it into "true"
	Edge1.Transparency = 0
	Edge2.Transparency = 0
	Edge3.Transparency = 0
	Edge4.Transparency = 0
	Edge5.Transparency = 0
	Edge6.Transparency = 0
	Edge7.Transparency = 0
	Edge8.Transparency = 0
	Edge9.Transparency = 0
	Edge10.Transparency = 0
	Edge11.Transparency = 0
	Edge12.Transparency = 0
	
	wait(2)
	Edge1.Transparency = 1
	Edge2.Transparency = 1
	Edge3.Transparency = 1
	Edge4.Transparency = 1
	Edge5.Transparency = 1
	Edge6.Transparency = 1
	Edge7.Transparency = 1
	Edge8.Transparency = 1
	Edge9.Transparency = 1
	Edge10.Transparency = 1
	Edge11.Transparency = 1
	Edge12.Transparency = 1
	
end)

Video how the UI works

PartUiGrab.wmv (2.3 MB)

Here is a photo from Exlorer

  • StarterGui
    Screenshot (32)

  • Part to be clicked
    Screenshot (31)

The issue i got

So my problem here is that I can’t make the Ui invisible anymore by pressing the yes/no button.

You can test the game via the following link
Test Game

I would be very grateful if you could help me. :happy3:

4 Likes

Don’t use game.StarterGui, as all GUI, when the game is started, is replicated to PlayerGui. Instead do this:

local plr = game.Players.LocalPlayer
local Grab = plr.PlayerGui.ScreenGui.GrabGui
3 Likes

StarterGui is fine to reference from a local script, it’s possible that the script belongs to StarterGui itself & they likely want to reference the ScreenGui inside StarterGui.

script.Parent... would be better though.

4 Likes

Ok i will try it

Thanks for helping me! :happy3:

1 Like

Instead of getting the parts one by one, you could use a loop to loop through game.Workspace.Edge:GetChildren().

2 Likes

Thank you for your help! :happy3:

1 Like

Has your problem been solved yet?

2 Likes

Alright, thanks for your advice! :happy2:

1 Like

The “No” button works. But the “Yes” button still doesn’t work.
Here’s the script.

local tool = game.ReplicatedStorage.Bricks 
local plr = game.Players.LocalPlayer
local Grab = plr.PlayerGui.ScreenGui.GrabGui

script.Parent.MouseButton1Click:Connect(function() 
	tool:Clone() --clones tool
	tool:Clone().Parent = player.Backpack 
	Grab.Visible = false
end)

Can you help me?

1 Like

Which part of it doesn’t work?

2 Likes

The problem is the same, the UI cannot be closed/invisible

Thank you for your reply :happy3:

1 Like

Are there any errors in the output or anything useful that can help?

2 Likes

Here is a video about the “No” button already working fine and with Output.

Photo (Output)

Screenshot (34)

VIdeo

2021-10-27 18-03-25.wmv (2.4 MB)

1 Like

You defined the variable as plr, not player. Do this instead:

local tool = game.ReplicatedStorage.Bricks 
local plr = game.Players.LocalPlayer
local Grab = plr.PlayerGui.ScreenGui.GrabGui

script.Parent.MouseButton1Click:Connect(function() 
	local tool = tool:Clone() --clones tool
	tool.Parent = plr.Backpack 
	Grab.Visible = false
end)
2 Likes

Oh, Thank you so much you have helped me so far. :happy3:

2 Likes