Click on tool for gui to appear issue

Hello I’m making a system for my game where you click on a tool to see the gui but their is an issue with this and to my believe their is no output in studio

my code:


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

script.Parent.Unequipped:Connect(function()
	BookGUI:Destroy()
end)```

You don’t have a screengui. You’ll need one for the gui to appear.

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

script.Parent.Equipped:Connect(function()
	if not Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI") then
		local BookGUI = script.Parent:WaitForChild("BookGU"):Clone()
		BookGUI.Parent = Player:WaitForChild("PlayerGui")
	end
end)

script.Parent.Unequipped:Connect(function()
	if Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI") then
		Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI"):Destroy()
	end
end)
1 Like

explorer

1 Like

Sorry, I mean you need to clone the gui into a screengui inside of playergui

1 Like

this did not work the output said nothing

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

script.Parent.Equipped:Connect(function()
	if not Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI") then
        print("test")
		local BookGUI = script.Parent:WaitForChild("BookGUI"):Clone()
		BookGUI.Parent = Player:WaitForChild("PlayerGui")
	end
end)

script.Parent.Unequipped:Connect(function()
	if Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI") then
        print("test2")
		Player:WaitForChild("PlayerGui"):FindFirstChild("BookGUI"):Destroy()
	end
end)

Do these prints print out?

I think I’ve found it. I forgot to put the ‘I’ in the ‘BookGui’. Try it now.

Yeah this did work for the print but other apart from that no

Is this running from a local script or normal script?

local BookGUI = script.Parent:WaitForChild("BookGUI")
local BookGUIClone = BookGUI:Clone()
BookGUIClone.Parent = Player:WaitForChild("PlayerGui")

I have 2 questions:

1: Is this a server script or a local script?
2: Why are you using
if not game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("BookGUI") then. Why is there a not in there?

Sorry for late response its from local

I did use a YouTube tutorial
char limit

I tried the script like this:


local BookGUIClone = BookGUI:Clone()

BookGUIClone.Parent = Player:WaitForChild("PlayerGui")

script.Parent.Unequipped:Connect(function()

BookGUI:Destroy()

end)

--Didnt work

Output:

Workspace.EruptingStudiosGD.Book.LocalScript:3: attempt to index nil with 'WaitForChild'

That means your ‘Player’ variable is ‘nil’. How is ‘Player’ defined in the script?

I’m not to sure since I used a youtube tutorial If you want i can link it