Equipped is not a valid member of PlayerGui

I am creating a tool that tells you the BrickColor of any part when you hover over it with your mouse. However, I keep getting the error "Equipped is not a valid member of PlayerGui “Players.comfycouchman.PlayerGui”. I know exactly whats causing this, but I can’t think of any solutions. It’s 11:30 PM and my brain is pretty much fried lol

Heres my local script:

 local screengui = script.Parent
local frame = screengui.Frame
local tool = frame.Parent.Parent
local colorImage = frame.ColorFrame.ColorImage
local colorTitle = frame.ColorTitle

local players = game:GetService("Players")
local player = players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local mouse = player:GetMouse()

local CurrentGui = nil
local ToolEquipped = false

local function SetupGui()
	if CurrentGui then
		CurrentGui:Destroy()
	end	

	CurrentGui = screengui:Clone()
	CurrentGui.Parent = PlayerGui
end

tool.Equipped:Connect(function()
	if ToolEquipped then return end 
	ToolEquipped = true
	
	mouse.Move:Connect(function()
		frame.Position = UDim2.new(0, mouse.X + 25, 0, mouse.Y + 5)
		frame.Visible = false
		local target = mouse.Target
		if target and target.Parent then
			if target.Parent.ClassName == "BasePart" and target:IsAncestorOf(game.Workspace.Map) then
				colorImage.BackgroundColor3 = Color3.new(target.Color)
				colorTitle.Text = target.BrickColor.Name
				frame.Visible = true
			
			elseif target.Parent.ClassName == "Model" then
				colorImage.BackgroundColor3 = target.Color
				colorTitle.Text = target.BrickColor.Name
				frame.Visible = true
			end
		end
		SetupGui()
	end)
end)

tool.Unequipped:Connect(function()
	if not ToolEquipped then return end 
	ToolEquipped = false
	
	if CurrentGui then
		CurrentGui:Destroy()
	end
	
	CurrentGui = nil
end)

The error is indicating that you’re trying to index/find something called Equipped inside of the PlayerGui. This is likely because the reference you have for the tool on the third line is referring to the PlayerGui folder instead of the location of the tool.

Okay. Now how do I find the actual tool and not the PlayerGui folder?

When the player has the tool, it’ll be in their Character if equipped & in their Backpack if unequipped. While you can reference it that way, I’m not sure where the tool is in the game prior to that, so I don’t know what the reference would be adjusted to aside from looking through their Character/Backpack.

2 Likes