Help with weapon wheel script

So,what I had in my mind is making a weapon wheel with different weapon categories (such as assault rifles,shotguns,handguns,etc),something similar to the weapon wheels in gta games.

This weapon wheel is made of multiple frames that form the shape of a circle,each one represents a different gun category, you can choose you’re weapon with a spinning arrow at the middle of the circle and uppon clicking on the choosen gun, the player will equip the gun,the script will filter the gun by categories by finding a child on it,the child will be a part inside the gun(tool) that will have the name of the gun category (for example shotguns will have a part with the name “shotgun”).
After that it will add a image label with the gun image to the sector (frame) where it belongs to,when clicking the frame the script will fire a remote event that will cause the player to equip the chosen gun.

The problem comes when I test the script and I open the weapon wheel using right click,when I do I see the Pistol image on the pistols sector,the spinning arrow works fine too,however when I want to click on the pistol I get an error on the output that says
"TOOL NAME is not a valid member of Frame “StarterGui.WeaponWheel.InventoryFrame.GunWheelHeavyGuns” "
“GunWheelHeavyGuns” It’s just another gun sector and sometimes the error mentions other sectors and not only the Heavy guns one.

Something to take in considerations is that I copied some pars of this script from youtube, and I’m not the best at scripting so I don’t know what is causing the error.

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

script.Parent.Enabled = false

local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local mouse = game.Players.LocalPlayer:GetMouse()
local camera = workspace.CurrentCamera

local currentlyHovering = nil

local count = 0

local pointer = script.Parent:WaitForChild("Pointer")
local frame = script.Parent.InventoryFrame
local circumference = frame.AbsoluteSize.X * math.pi

uis.InputBegan:Connect(function(inp, p)
	if inp.UserInputType == Enum.UserInputType.MouseButton2 and not p then

		script.Parent.Enabled = not script.Parent.Enabled

	end

end)

function updateSectors()
    ---------------------------------tools(guns yes)-------------------------------------------------------------
	local tools = game.Players.LocalPlayer.Backpack:GetChildren()
	----------------------------------------------------------------------------------------------
	if game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") then
		table.insert(tools, game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool"))
	end
	count = #tools
	----------------------------------------------------------------------------------------------
	table.sort(tools, function(a, b)
		return a.Name < b.Name
	end)

	local absoluteSectorWidth = (circumference / count)
	local sectorWidth = absoluteSectorWidth / frame.AbsoluteSize.X
    ---------------------------------------------Sectors Variables-------------------------------------------
	for i, tool in pairs(tools) do                                  
		local pistolSector = script.Parent.InventoryFrame.GunWheelPistol -- Pistols
		local SubmachinegunsSector = script.Parent.InventoryFrame.GunWheelSubMachineGuns -- Submachineguns
		local AssaultRiflesSector = script.Parent.InventoryFrame.GunWheelAssaultRifles -- AssaultRifles
		local ShotgunsSector = script.Parent.InventoryFrame.GunWheelShotguns -- Shotguns
		local HeavySector = script.Parent.InventoryFrame.GunWheelHeavyGuns -- HeavyGuns
		local SpecialSector = script.Parent.InventoryFrame.GunWheelSpecials -- SpecialGuns
		local MeleeSector = script.Parent.InventoryFrame.GunWheelMelee -- Melee
	---------------------------------------------------------------------------------------------------	
		local rotation = (i-1) * (360/count)
	---------------------------------Creating Image labels on each sector------------------------------------------------------------------
	if tool:FindFirstChild("Pistol") then --------------------------------- Pistols
		local PistolDisplay = Instance.new("ImageLabel")
		PistolDisplay.Parent = pistolSector
		PistolDisplay.Name = tool.Name
		PistolDisplay.Image = tool.TextureId
		PistolDisplay.Size = UDim2.new(1,0, 1,0)
		PistolDisplay.BorderSizePixel = 0
		PistolDisplay.Rotation = 210
			PistolDisplay.Name = i
	elseif tool:FindFirstChild("Submachinegun") then ---------------------- Submachineguns
			local SubDisplay = Instance.new("ImageLabel")
			SubDisplay.Parent = SubmachinegunsSector
			SubDisplay.Name = "PistolDisplay"
			SubDisplay.Image = tool.TextureId
			SubDisplay.Size = UDim2.new(1,0, 1,0)
			SubDisplay.Name = i
	elseif tool:FindFirstChild("Assault") then ----------------------------- Asauult Rifles
			local AssaultDisplay = Instance.new("ImageLabel")
			AssaultDisplay.Parent = AssaultRiflesSector
  		    AssaultDisplay.Name = "PistolDisplay"
			AssaultDisplay.Image = tool.TextureId
			AssaultDisplay.Size = UDim2.new(1,0, 1,0)
			AssaultDisplay.Name = i
	elseif tool:FindFirstChild("Shotgun") then  ---------------------------- Shotguns
			local ShotgunDisplay = Instance.new("ImageLabel")
			ShotgunDisplay.Parent = ShotgunsSector
			ShotgunDisplay.Name = "PistolDisplay"
			ShotgunDisplay.Image = tool.TextureId
			ShotgunDisplay.Size = UDim2.new(1,0, 1,0)
			ShotgunDisplay.Name = i
	elseif tool:FindFirstChild("Heavy") then -------------------------------- Heavy Guns
			local HeavyDisplay = Instance.new("ImageLabel")
			HeavyDisplay.Parent = HeavySector
			HeavyDisplay.Name = "PistolDisplay"
			HeavyDisplay.Image = tool.TextureId
			HeavyDisplay.Size = UDim2.new(1,0, 1,0)
			HeavyDisplay.Name = i
	elseif tool:FindFirstChild("Special") then ------------------------------ Special Guns
			local SpecialDisplay = Instance.new("ImageLabel")
		    SpecialDisplay.Parent = HeavySector
			SpecialDisplay.Name = "PistolDisplay"
			SpecialDisplay.Image = tool.TextureId
			SpecialDisplay.Size = UDim2.new(1,0, 1,0)
			SpecialDisplay.Name = i
	elseif tool:FindFirstChild("Melee") then
			local MeleeDisplay = Instance.new("ImageLabel") ----------------- Melee Weapons
			MeleeDisplay.Parent = MeleeSector
			MeleeDisplay.Name = "PistolDisplay"
			MeleeDisplay.Image = tool.TextureId
			MeleeDisplay.Size = UDim2.new(1,0, 1,0)
			MeleeDisplay.Name = i
	else
		print("No guns Equipped")
	end
	

	-----------------------------------------------------------------------	
	if tool:FindFirstChild("Pistol") then
	local PistolDisplay = pistolSector:FindFirstChildOfClass("ImageLabel")
    local PistolValue = Instance.new("StringValue")
	PistolValue.Name = "TOOL NAME"
	PistolValue.Value = tool.Name
	PistolValue.Parent = PistolDisplay
	end
	-----------------------------------------------------------------------
	if tool:FindFirstChild("Submachinegun") then
	local SubDisplay = SubmachinegunsSector:FindFirstChildOfClass("ImageLabel")
	local SubValue = Instance.new("StringValue")
	SubValue.Name = "TOOL NAME"
	SubValue.Value = tool.Name
	SubValue.Parent = SubDisplay
	end
	-----------------------------------------------------------------------
	if tool:FindFirstChild("Assault") then
	local AssaultDisplay = AssaultRiflesSector:FindFirstChildOfClass("ImageLabel")
	local AssaultValue = Instance.new("StringValue")
	AssaultValue.Name = "TOOL NAME"
	AssaultValue.Value = tool.Name
	AssaultValue.Parent = AssaultDisplay 
	end
	-----------------------------------------------------------------------
	if tool:FindFirstChild("Shotgun") then
	local ShotgunsDisplay = ShotgunsSector:FindFirstChildOfClass("ImageLabel")
	local ShotgunsValue = Instance.new("StringValue")
    ShotgunsValue.Name = "TOOL NAME"
	ShotgunsValue.Value = tool.Name
	ShotgunsValue.Parent = ShotgunsDisplay
	end
	------------------------------------------------------------------------
	if tool:FindFirstChild("Heavy") then
	local HeavyDisplay = HeavySector:FindFirstChildOfClass("ImageLabel")
	local HeavyValue = Instance.new("StringValue")
	HeavyValue.Name = "TOOL NAME"
	HeavyValue.Value = tool.Name
	HeavyValue.Parent = HeavyDisplay
	end
	------------------------------------------------------------------------
	if tool:FindFirstChild("Special") then
	local SpecialDisplay = SpecialSector:FindFirstChildOfClass("ImageLabel")
	local SpecialValue = Instance.new("StringValue")
	SpecialValue.Name = "TOOL NAME"
	SpecialValue.Value = tool.Name
	SpecialValue.Parent = SpecialDisplay
	end
	------------------------------------------------------------------------
	if tool:FindFirstChild("Melee") then
	local MeleeDisplay = MeleeSector:FindFirstChildOfClass("ImageLabel")
	local MeleeValue = Instance.new("StringValue")
	MeleeValue.Name = "TOOL NAME"
	MeleeValue.Value = tool.Name
	MeleeValue.Parent = MeleeDisplay
	end
	----------------------------------------------------------------------------
end

end

    ---------------------Calling the function-------------------------
	updateSectors()
	game.Players.LocalPlayer.Backpack.ChildAdded:Connect(updateSectors)
	game.Players.LocalPlayer.Backpack.ChildRemoved:Connect(updateSectors)
	game.Players.LocalPlayer.Character.ChildAdded:Connect(updateSectors)
	game.Players.LocalPlayer.Character.ChildRemoved:Connect(updateSectors)
	------------------------------------------------------------------

------------------------------------Equip the choosed gun on click----------------------------------
mouse.Button1Up:Connect(function()
	if currentlyHovering and script.Parent.Enabled == true then
		game.ReplicatedStorage:WaitForChild("InventoryRE"):FireServer(currentlyHovering["TOOL NAME"].Value)
		script.Parent.Enabled = false
	end
end)

--------------Rotate the pointer and check which tool the player is choosing on,this works fine already--------
rs.Stepped:Connect(function()
------------------------------------------------------------------------
local Sectors = game.StarterGui.WeaponWheel.InventoryFrame:GetChildren()
------------------------------------------------------------------------
	if count > 0 and script.Parent.Enabled == true then
		local x, y = mouse.X, mouse.Y
		local viewportSize = camera.ViewportSize / 2

		local angle = math.deg(math.atan2(y - viewportSize.Y, x - viewportSize.X)) - 90
		if angle < 0 then
			angle = angle + 360
		end
		
		pointer.Rotation = angle

		local space = 360/count/2
		for i = 1, count do
			local degrees = (i-1) * (360/count)

			local min = degrees - space
			local max = degrees + space

			if min < 0 then
				min = min + 360
			end	
			if (angle > min and angle < max) or (i == 1 and (angle > min or (angle < max and angle >= 0))) then
				currentlyHovering = Sectors[i]
			end
		end
	end
end)

Here is the remote event by the way

----------
local re = game.ReplicatedStorage:WaitForChild("InventoryRE")

--Equip tool on client request
re.OnServerEvent:Connect(function(player, toolName)
	if player.Character and toolName then

		if player.Backpack:FindFirstChild(toolName) then
			player.Character.Humanoid:EquipTool(player.Backpack[toolName])

		elseif player.Character:FindFirstChild(toolName) then
			player.Character.Humanoid:UnequipTools()
		end
	end
end)
1 Like

I made it work,I still get an error that prints
"1 is not a valid member of Frame “Players.Damvillah0.PlayerGui.WeaponWheel.InventoryFrame.GunWheelSubMachineGuns” but I made it work

That might be a problem but whatever

Uhhhhhhhhhhhhhhhh,Now the script does’nt detect the gun as equipped even if it is.