Scripting Tools to Open a Gui

So I’ve been building and scripting a new game and I hit a tough spot when coding some tools. I’m trying to make it so when a book tool is opened/clicked on, a gui opens with it and when a book tool is closed/clicked out of, the gui closes as well.

I’ve looked for tutorials and such but can’t seem to find anything, does anyone have any guidelines or tutorials that may be helpful?

Thanks!
(I think I put this in the right category, I didn’t see something for scripting and gui help and this is a majority scripting issue.)

You can use something very basic like this, make sure to put this in a LocalScript in the tool you want to have this effect. Also, I’ve used a ScreenGui’s Frame as an example, but you’ll want to rename this to the path of whatever you’re trying to change.

local Tool = script.Parent
local plr = game.Players.LocalPlayer

local OnScreen = false 

Tool.Activated:Connect(function()
	if OnScreen == false then
		plr.PlayerGui.ScreenGui.Frame.Visible = true 	
		OnScreen = true
	else
		plr.PlayerGui.ScreenGui.Frame.Visible = false
		OnScreen = false
	end
end)

Tool.Unequipped:Connect(function()
	plr.PlayerGui.ScreenGui.Frame.Visible = false
	OnScreen = false 
end)

Alright, Ill try that. Thanks.

local players = game:GetService"Players"
local player = players.LocalPlayer

local tool = script.Parent

tool.Activated:Connect(function()
	player.PlayerGui.ScreenGui.Frame.Visible = not player.PlayerGui.ScreenGui.Frame.Visible
end)

tool.Unequipped:Connect(function()
	player.PlayerGui.ScreenGui.Frame.Visible = false
end)
1 Like

Hey,

Both @alphadoggy111 and @Forummer gave you a solution, Forummer just shortened it.

You might want to take a look on both

Yeah thanks, I ended up doing something more like this:

local ScreenGui

script.Parent.Equipped:Connect(function()
	if not game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ScreenGui") then
		ScreenGui = script.Parent.ScreenGui:Clone()
		ScreenGui.Parent = game:GetService("Players").LocalPlayer.PlayerGui
	end
end)

script.Parent.Unequipped:Connect(function()
	ScreenGui:Destroy()
end)