Hello there! First off the way I would replicate what you're trying to accomplish would be to check the amount of tools in the backpack. Once you do that, you want to remove all extra tools. I won't code the entire thing for you but I will give you a base of code that would work in your favor. To clarify, this is a LocalScript and a ServerScript will not work under Filtering Enable Conditions.
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 | repeat wait() until Player.Character ~ = nil |
04 | local Character = Player.Character |
06 | local Backpack = Player.Backpack |
09 | local function CheckAmount(Object) |
11 | for ToolIndex,Tool in pairs (Backpack:GetChildren()) do |
18 | Backpack.ChildAdded:Connect(CheckAmount) |
19 | Character.ChildAdded:Connect(CheckAmount) |
As you can see, in this small block of code I've already solved one of your problems. Now the second thing you must go into finding out is swapping weapons that I assume you want to swap with on the ground. For dropped weapons, I would have NPC's or however you want them on the ground placed in a folder in the workspace. There you can get the distance between you and the weapon itself. Here is an example.
01 | local WeaponFolder = workspace.WeaponsFolder |
04 | for _,Weapon in pairs (WeaponFolder:GetChildren()) do |
05 | local Magnitude = (Character.HumanoidRootPart.Position -Weapon.Handle.Position).magnitude |
06 | if Magnitude < = MaxDistance then |