Inventory Wheel || Help

What I want: I want the player to have only one weapon that he equipped last from the inventory and delete other weapons in his inventory.

The issue is that I don’t know how to do that. I would like to get some suggestions on how I could script that :slight_smile:

Any corrections in my current script will be appreciated too.

Here’s the script:

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://11825958589"
sound.Parent = script.Parent:WaitForChild("SoundEffects")

local Name = script.Parent:WaitForChild("Name")
Name.Visible = false

local Selected = false

local Selection = script.Parent:WaitForChild("Selection")
local RS = game:GetService("ReplicatedStorage")
local Weapons = RS:WaitForChild("Weapons")

for _, plr in pairs(game.Players:GetPlayers()) do
	for _, Select in pairs(Selection:GetDescendants()) do
		if Select:IsA("ImageButton") then
			Select.MouseEnter:Connect(
				function()
					sound:Play()
					
					if Selected == false then
						Select.ImageColor3 = Color3.new(0.176471, 0.431373, 0.72549)
						Selected = true
					end

					for _, Icon in pairs(Select:GetDescendants()) do
						Name.Visible = true
						Name.Text = Icon.Name

						local tool = Weapons:FindFirstChild(Icon.Name)
						
						local char = plr.Character or plr.CharacterAdded:Wait()
						local hum = char:FindFirstChildOfClass("Humanoid")
						hum:UnequipTools()
						
						if Icon.Name == "Fist" then
							return
						else
							if plr.Backpack:FindFirstChild(Icon.Name) then
								return
							else
								coroutine.wrap(
									function()
										local t = tool:Clone()
										t.Parent = plr.Backpack
										hum:EquipTool(t)
									end)()
							end
							
						end
					end
				end)

			Select.MouseLeave:Connect(
				function()
					if Selected == true then
						Select.ImageColor3 = Color3.new(0.0470588, 0.0470588, 0.0470588)
						Selected = false		
					end
				end)
		end
	end
end


2 Likes

I answered you under the topic you made about the same thing recently.

use a for loop when the player selects a weapon to remove all weapons from the players backpack (ex: :Destroy()) and then put the new weapon in the players backpack. do this for all weapons except the fist.

I don’t know what you’re trying to do exactly, but here’s how you can equip a tool to a humanoid:
local part = script.Parent
local player = game.Players:GetPlayerFromCharacter(part.Parent)
local tool = script.Parent:WaitForChild(“Tool”)
local humanoid = player.Character:WaitForChild(“Humanoid”)

local playerMouse = player:GetMouse()
while wait() do
if playerMouse:IsButtonPressed(0) then
humanoid:EquipTool(tool)
end
end