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

How do I make a ScreenGUI pop up when I equip my Gun?

Asked by 6 years ago

So basically, I need a GUI to pop up on the screen(its for ammo) when I equip my gun! I tried to put a ScreenGUI with frames and stuff inside the Handle of the gun... it does not show up when I grab the gun. I have looked at free models and the screengui is just inside the tool. I wish to make it like this... I tried to do a script where the screen gui is enabled when I equip the tool, it did not work. -- The big part is.. I need a GUI to pop up when I equip a tool, and the GUI must be able to be changed as values within the tool's local script is changed. Thank you!!!

2 answers

Log in to vote
0
Answered by
Scaii_0 145
6 years ago

So to have a function on a tool (your gun) being equipped you would have to use Tool:Equipped.

So in order to use this, first you need to set up a local way of getting to your gun and your player. Therefore I recommend putting the script in the GUI for the ammo.

local gui =  script.Parent
local player = script.Parent.Parent
local tool = player.Backpack:WaitForChild("Gun") --Or if you have other ways of getting to the gun

Now you have your'e local's you can access the gun and function when its equipped like this:

local gui =  script.Parent
local player = script.Parent.Parent
local Tool = player.Backpack:WaitForChild("Gun") --Or if you have other ways of getting to the gun

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

And if you want to make it disappear when its unequipped you can make another function after the end using Tool:Unequipped. Using the wiki page here and the current script you could figure out what you need to do.

0
As for the variables in the gun, they can be accessed in the same way. Tool.VariablesHere.Value. Also I don't recommend that you look through free models, they will be unreliable and some are infected and could damage your game without you knowing where its coming from. Scaii_0 145 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

im not familar at all with tools but probably something like

if gun.beingheld = true then -- not sure what the correct term is for beingheld
ammogui.Visible = true
if gun.beingheld = false then
ammogui.Visible = false

Answer this question