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
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