Problem with GUI Magnitude code

Yes I do, should I change the name?

No, just drag the localscript inside button and paste this script in it:

local GUI = script.Parent
local open = GUI:FindFirstChild("FrameOpen").Open
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Root = Character:FindFirstChild("HumanoidRootPart")
local PressE = game.Workspace:FindFirstChild("PressE")

script.Parent.MouseButton1Click:Connect(function()
   local Distance = (Root.Position - PressE.Position).Magnitude
   print ("Distance")
if Distance < 15 then
   print("Distance is less than 15!")
   Player.PlayerGui.OpenGui.Frame.Visible = true
  end
end)

Here is what happens:
Players.MegaTheMagnificent.PlayerGui.OpenGUI.FrameOpen.Open.GuiScript:2: attempt to index a nil value

ugh just remove open variable please. Like this and try again:

Not working, hope this helps find the problem.


I am confused now which gui would you like to be visible? Because in OpenGui you have frame named FrameOpen and you are calling this frame with name Frame inside script.

I’m trying to open the frame and the button.

Yes but you have 3 ScreenGuis and 2 of them have an frame inside so which one would you like to be become visible?

1 Like

FrameOpen is the one I’m trying to open and then the button inside FrameOpen.

if you have FrameOpen Frame invisible how are you going to be possible to see the button you are activating the script? Didn’t you move the script inside button as I told you?

Yeah, I moved the localscript inside the button. Maybe if I changed it to enable the screen GUI?

Inside Open button? How are you then possible to see the button if you have FrameOpen set invisible as default?

What if I changed the Player.PlayerGui.OpenGui.Frame.Visible = true
To Player.PlayerGui.OpenGui.Enabled = true

Dude, I am sorry I am trying my best to understand where you local script is located right now because you are saying that you moved the script inside button and from the image is seen that you moved it into Open button which parent of it is FrameOpen which is set invisible as default and at this point, you wouldn’t be even available to see the button. If you’d like to have a screen GUI button then create a new screen GUI and add button inside and paste the following code I sent you above also you will have to change this:

Player.PlayerGui.OpenGui.Frame.Visible = true

to this:

Player.PlayerGui.OpenGui.FrameOpen.Visible = true

Okay I did what you said, now where do I put the local script? In the button or the ScreenGui?

In the button of the new screen gui.

MouseButton1Click is not a valid member of frame. You said frame.

You have to add button not frame inside new screengui.

MouseButton1Click is not a valid member of TextBox.

Oh I though you use MouseButton1Down well use this functions instead then inside button.