I am working on a FPS game and i am trying to make it so that the current tool gtets unequipped when someone changes their gun.
This is what i have so far:
wait(1)
local p = game.Players.LocalPlayer
local c = p.Character
local m = p:GetMouse()
local startergui = game:GetService('StarterGui')
startergui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
p.CameraMode = Enum.CameraMode.LockFirstPerson
local gun = game.ServerStorage.Pistol:Clone()
gun.Parent = p.Backpack
c.Humanoid:EquipTool(gun)
m.KeyDown:Connect(function(key)
if key == "1" and p.Data.Current.Value ~= "Primary" then
p.Data.Current.Value = "Primary"
c:FindFirstChild(p.Data.Primary.Value):Remove()
p.PlayerGui.mainGUI:Remove()
local gun = game.ServerStorage:FindFirstChild(p.Data.Primary.Value):Clone()
gun.Parent = p.Backpack
c.Humanoid:EquipTool(gun)
end
end)
m.KeyDown:Connect(function(key)
if key == "2" and p.Data.Current.Value ~= "Secondary" then
p.Data.Current.Value = "Secondary"
c:FindFirstChild(p.Data.Secondary.Value):Remove()
p.PlayerGui.mainGUI:Remove()
local gun = game.ServerStorage:FindFirstChild(p.Data.Secondary.Value):Clone()
gun.Parent = p.Backpack
c.Humanoid:EquipTool(gun)
end
end)
This works and all, but i would prefer a way to forcefully unequip a tool instead of removing the tool itself.
Thanks!

1 comment
You have use EquipTool and there is the reverse operation http://wiki.roblox.com/index.php?title=API:Class/Humanoid/UnequipTools