How to create a tool that makes a ScreenGui visible when equipped

The problem

I need to make a tool that opens a ScreenGui when its equipped.

I’ve tried looking for scripts by other developers and even tutorials online, but nothing I’ve found has come close to what I need.

(I’m not looking for a scripter to do the work for me. I want to LEARN how to do this so I can do it again in the future if needed.)

Optional: I would also prefer that the player’s arm doesn’t raise when the tool is equipped, since the tool is going to be invisible. I’m not sure how difficult this would be to implement, so it’s fine if it gets left out.

2 Likes

There is an event when a tool is equipped that fires. You can connect this to anything.

tool.Equipped:Connect(function()

print("tool equipped")

PlayerGui.ScreenGui.Visible = true
end)

Wiki:

3 Likes

Since PlayerGui is clientsided, should I use a LocalScript or a Script?

Use a Local Script. You wont be able to detect a tool being equipped from the server. (I think)

1 Like

It depends on how you want it done you can clone a GUI with a client or local script in place it in the Player’s GUI then remove on a de-equip function or just make it visible.

Everything works like a charm, but PlayerGui.script1 (the ScreenGui) doesn’t enable.

tool = script.Parent

tool.Equipped:Connect(function()

print("tool equipped")

PlayerGui.script1.Enabled = true
end)

tool.Unequipped:Connect(function()
	
	print("tool unequipped")
	
	PlayerGui.script1.Enabled = false
end)

You’re able to detect it as “Equipped” event works for both client and sever, and server-side script runs perfectly in a player’s backpack.

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui

You have these lines, right? Because I can’t think of any other problem here but “PlayerGui” being a StarterGui

If you are trying to make a screen gui appear called script, you are doing it right. If you are trying to enable/disable a script. Its the opposite function name as gui.

Gui.Enabled = true--Gui Will Appear
Gui.Enabled = false--Gui Will Not Appear

Script.Disabled = false--Script Will Run
Script.Disabled = true--Script Will Not Run
1 Like

Yeah, I’m aware of the difference. That’s why I put “(the ScreenGui)” in my reply.

Now I’m having client/server script issues.

v Normal Script

v LocalScript

2020-06-08 (4)

No matter what type of script I use, something causes it to break.

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui

tool = script.Parent

tool.Equipped:Connect(function()

print("tool equipped")

PlayerGui.script1.script1.Visible = true
end)

tool.Unequipped:Connect(function()
	
	print("tool unequipped")
	
	PlayerGui.script1.script1.Visible = false
end)

did you put your local script in the tool or the tool.Handle?

I put the localscript in tool.Handle
Was I not supposed to?

Yes, you should have it in the tool instead. Sorry for not mentioning that earlier :sweat_smile:

1 Like

If you want the player’s arm to not raise, turn off RequiresHandle.