The tool GUI is never shown when the tool is equipped

Hello fellow devs!

I am developing special vacuum cleaners for CO2 as tools right now.
I want to show a tool GUI (screen GUI) displaying the tool name, the current load and the max load only when the tool is equipped.

When I tested, there are no error messages, but the GUI is never shown.
Below is the code:

--Services--
local StarterGui = game:GetService("StarterGui")

-- Models and parts--
local tool = script.Parent
local head = tool.Head
local cone = tool.Cone

local player = game:GetService("Players"):WaitForChild("LocalPlayer")

-- Values --
local maxLoad = tool:WaitForChild("MaxLoad").Value

-- GUI --
local toolGui = StarterGui:WaitForChild("ToolGui")
local loadFrame = toolGui:WaitForChild("LoadFrame")
local toolNameLabel = loadFrame.ToolName
local currentLoadLabel = loadFrame.CurrentLoadLabel
local maxLoadLabel = loadFrame.MaxLoadLabel

-- Sounds --
local vacuumCleanerSound = tool:WaitForChild("VacuumCleanerSound")

-- Constance --
local SUCKINGPOWER = 10000
local currentLoad = 0

-- Tool Events --
tool.Equipped:Connect(function()
	
	toolGui.Enabled = true        --Display Tool GUI
	
	vacuumCleanerSound:Play()
	print("Tool Equipped")
	
	toolNameLabel.Text = tool.Name
	maxLoadLabel.Text = maxLoad
	
	local ap_a1 = Instance.new("Attachment", head)
	

	while wait(.1) do
		local aoe = workspace:GetPartsInPart(cone)
		for _, a in pairs(aoe) do
			if a.Parent and a.Parent.Name == "CO2" then
				local CO2 = a.Parent
				local ap_a0 = Instance.new("Attachment", CO2.Carbon)

				local alignPosition = Instance.new("AlignPosition", CO2.Carbon)
				alignPosition.Mode = "TwoAttachment"
				alignPosition.Attachment0 = ap_a0
				alignPosition.Attachment1 = ap_a1
				alignPosition.MaxForce = SUCKINGPOWER

				print("Found a CO2")

			end
		end
	end
end)


tool.Unequipped:Connect(function()
	
	toolGui.Enabled = false  -- Hide Tool GUI
	vacuumCleanerSound:Stop()
	
end)


head.Touched:Connect(function(hit)
	if hit.Parent and hit.Parent.Name == "CO2" and currentLoad < maxLoad then
		hit.Parent:Destroy()
		currentLoad +=1
		currentLoadLabel.Text = tostring(currentLoad)
	end
end)

If you want, pls check the folder structures on the right side below:

Now I am at a loss what to do next.
So please help me!

set it on the Player.PlayerGui and not StarterGui

also what
local player = game:GetService("Players"):WaitForChild("LocalPlayer")
its a property, not an instance

-- Models and parts--
local tool = script.Parent
local head = tool.Head
local cone = tool.Cone

local player = game:GetService("Players").LocalPlayer -- and what

-- Values --
local maxLoad = tool:WaitForChild("MaxLoad").Value

-- GUI --
local toolGui = player:WaitForChild("PlayerGui"):WaitForChild("ToolGui")
local loadFrame = toolGui:WaitForChild("LoadFrame")
local toolNameLabel = loadFrame.ToolName
local currentLoadLabel = loadFrame.CurrentLoadLabel
local maxLoadLabel = loadFrame.MaxLoadLabel

-- Sounds --
local vacuumCleanerSound = tool:WaitForChild("VacuumCleanerSound")

-- Constance --
local SUCKINGPOWER = 10000
local currentLoad = 0

-- Tool Events --
tool.Equipped:Connect(function()
	
	toolGui.Enabled = true        --Display Tool GUI
	
	vacuumCleanerSound:Play()
	print("Tool Equipped")
	
	toolNameLabel.Text = tool.Name
	maxLoadLabel.Text = maxLoad
	
	local ap_a1 = Instance.new("Attachment", head)
	

	while wait(.1) do
		local aoe = workspace:GetPartsInPart(cone)
		for _, a in pairs(aoe) do
			if a.Parent and a.Parent.Name == "CO2" then
				local CO2 = a.Parent
				local ap_a0 = Instance.new("Attachment", CO2.Carbon)

				local alignPosition = Instance.new("AlignPosition", CO2.Carbon)
				alignPosition.Mode = "TwoAttachment"
				alignPosition.Attachment0 = ap_a0
				alignPosition.Attachment1 = ap_a1
				alignPosition.MaxForce = SUCKINGPOWER

				print("Found a CO2")

			end
		end
	end
end)


tool.Unequipped:Connect(function()
	
	toolGui.Enabled = false  -- Hide Tool GUI
	vacuumCleanerSound:Stop()
	
end)


head.Touched:Connect(function(hit)
	if hit.Parent and hit.Parent.Name == "CO2" and currentLoad < maxLoad then
		hit.Parent:Destroy()
		currentLoad +=1
		currentLoadLabel.Text = tostring(currentLoad)
	end
end)
2 Likes

Now I is working prettty good.
Thank you so much for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.