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!
its possible, just move the tool to the player's "Backpack"
when equipped:
tool appears in the players model (game.Workspace.PLAYERNAME)
when NOT equipped:
the tool is stored in a folder located in the player's "Player" instance called "Backpack" (game.Players.PLAYERNAME.Backpack)
by the way, its a good habit to indent your code