Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This script will allow a tool to equip but not unequip?

Asked by 7 years ago

Now I have come to the issue when making my own backpack. I can equip tools but I cannot unequip them. I am a fairly new scripter, so I am confused. Here is the script:

local btn = script.Parent
local plr = game.Players.LocalPlayer
local knife = game.ServerStorage.SilverBlade
btn.MouseButton1Down:connect(function(hit)
    if hit then
        plr.Character.Humanoid:EquipTool(knife)
        if hit and plr.Character.Humanoid:EquipTool(knife) then
            plr.Character.Humanoid:UnequipTools()
        end
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

So basically when you equip a tool, it adds the tool to the character. So you can use the for i, v in pairs loop. Like this

local btn = script.Parent
local plr = game.Players.LocalPlayer
local knife = game.ServerStorage.SilverBlade
local ToolEquiped = false
btn.MouseButton1Down:connect(function(hit)
    if hit and ToolEquiped == false then
        plr.Character.Humanoid:EquipTool(knife)
    ToolEquiped = true
      elseif hit and ToolEquiped == true then
    for i, v in pairs(plr.Character:GetChildren()) do
        if v:IsA("Tool") then
            v:Destroy()
        end
    end
    ToolEquiped = false
    end
end)

Ad

Answer this question