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

How do i open a gui when a tool is equipped?

Asked by 7 years ago

I'm trying to make a GUI open when a tool is equipped but i can't seem to do it.

This is my script so far.

gui = script.ScreenGui.Begin
Tool = script.Parent

Tool.Equipped:connect(function(mouse)
gui.Visible = true
end)

I've tried looking for scripts on google and moving the gui in multiple places to no avail.

I'm probably doing something that's really simple wrong, but i can't figure this out.

2 answers

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

You have to put the GUI in the Player's PlayerGui.

Guis only function in the PlayerGui. I'm going to use the Clone() function to make a copy of the GUI and move it to the player's GUI. You should also be using a Local Script.

Example,

-- Local Script in the tool in StarterPack
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local gui = script:WaitForChild("ScreenGui")
local Tool = script.Parent

Tool.Equipped:connect(function(mouse)
    local guiClone = gui:Clone()
    guiClone.Visible = true
    guiClone.Parent = plrGui
end)
On line 4, I removed the Frame because the whole thing has to be in a ScreenGui to work, and just moving the frame we would lose the ScreenGui. I also made all the variables Local, like you should do.

Good Luck

If I helped, don't forget to click the accept button. It helps a lot.
Ad
Log in to vote
0
Answered by
StoIid 364 Moderation Voter
7 years ago
Edited 7 years ago

Maybe because for gui you put script.ScreenGuiwhen for tool you did script.Parent. Obviously this script is located inside a tool so try script.Parent.Parent.ScreenGui.Begin?

Answer this question