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:
01 | wait( 1 ) |
02 | local p = game.Players.LocalPlayer |
03 | local c = p.Character |
04 | local m = p:GetMouse() |
05 |
06 | local startergui = game:GetService( 'StarterGui' ) |
07 | startergui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false ) |
08 | p.CameraMode = Enum.CameraMode.LockFirstPerson |
09 |
10 | local gun = game.ServerStorage.Pistol:Clone() |
11 | gun.Parent = p.Backpack |
12 | c.Humanoid:EquipTool(gun) |
13 |
14 | m.KeyDown:Connect( function (key) |
15 | if key = = "1" and p.Data.Current.Value ~ = "Primary" then |
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