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.
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)
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.
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.