Previous weapon is not deletin

  1. What do you want to achieve? Keep it simple and clear!

Hello, so basically what I’m trying to achieve is to give player the weapon when they trigger the proximity event and delete the previous item in their inventory.

  1. What is the issue? Include screenshots / videos if possible!

there is no error it gives the weapon after the player trigger the proximity but is not deleting the the previous item…

local Ak47 = game.ReplicatedStorage:WaitForChild("Ak47")
local ProximityPrompt = workspace.Sw.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(player)
	if not player.Backpack:FindFirstChild(Ak47.Name) then
		print("Player doesn't have " .. Ak47.Name)
		Ak47:Clone()
		Ak47.Parent = player.Backpack
		print("Player doesn't have " .. Ak47.Name)
	else
		print("Player already have " .. Ak47.Name)
		
		for _,v in pairs(game.StarterPack:GetChildren()) do
				if v.Name == "ClassicSword" and not player.Backpack:FindFirstChild(Ak47.Name) then
				print(v.Name .. " has been deleted!")
				v:Destroy()
			end
		end
	end
end)

image
You are deleting the sword from starterpack instead of the player’s backpack or startergear

You can instead do:

if player.StarterGear:FindFirstChild("ClassicSword") then player.StarterGear:FindFirstChild("ClassicSword"):Destroy() end
1 Like

You have to check if its in the character aswell. Whenever the player equips a tool, the tool goes inside the character,

1 Like
local StarterPack = game:GetService("StarterPack")
local Replicated = game:GetService("ReplicatedStorage")
local Ak47 = Replicated:WaitForChild("Ak47")
local SW = workspace:WaitForChild("Sw")
local Prompt = SW:WaitForChild("ProximityPrompt")

Prompt.Triggered:Connect(function(Player)
	local Character = Player.Character
	local Backpack = Player.Backpack
	local StarterGear
	if Character and Backpack then
		local CharacterTool = Character:FindFirstChild(Ak47.Name)
		local BackpackTool = Backpack:FindFirstChild(Ak47.Name)
		if not (CharacterTool or BackpackTool) then
			local Ak47Clone = Ak47:Clone()
			Ak47Clone.Parent = Backpack
		elseif CharacterTool or BackpackTool then
			local Sword = Backpack:FindFirstChild("ClassicSword")
			if Sword then
				Sword:Destroy()
			end
		end
	end
end)

This is working on my end, I believe this is what you were trying to achieve.

Proof:
https://gyazo.com/402084cbd35d9f190e149a9145786ad7

Here’s the model file.

repro.rbxm (4.4 KB)

I have tried your solution. But for some reason is not deleing the sword.

What am trying to achieve is to only allow players to have a tool at a time. When they interact with the prox if they have any tool in that exist in their inventory. Then it will delete em and clone the Ak47 or any other tool.