If the tool is located in his backpack, this is how you would do it:
What you want to do is first create a function to find the tool. Next, create a function to destroy the tool. Here's how:
local tool = ServerStorage.Tools.AzureSword
local function FindItemFromBackpack(whichItemName, whichPlayer)
local playerBackpack = whichPlayer.Backpack
local playerBackpackChilds = playerBackpack:GetChildren()
for _, eachItem in pairs(playerBackpackChilds) do
if eachItem.Name == whichItemName then
return eachItem
end
end
end
local function DestroyTool(whichTool, whichPlayer)
local toolInBackpack= FindItemFromBackpack(tool.Name, player)
if toolInBackpack then
toolInBackpack:Destroy()
toolInBackpack = nil
end
end
ReplicatedStorage.ShopFunctions:WaitForChild("Ninjago").OnServerInvoke = function(player)
local myDebounce = true
if player.leaderstats.Money.Value >= 500 and MyDebounce == true and player then
MyDebounce = false
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 500
DestroyTool(tool, player)
end
end
If it's located in his character then you would look through his character and not his backpack. If you want to make sure it's neither in his backpack nor his character then you would look at both of them and destroy the both. Here's how:
local tool = ServerStorage.Tools.AzureSword
local function FindItemFromBackpack(whichItemName, whichPlayer)
local playerBackpack = whichPlayer.Backpack
local playerBackpackChilds = playerBackpack:GetChildren()
for _, eachItem in pairs(playerBackpackChilds) do
if eachItem.Name == whichItemName then
return eachItem
end
end
end
local function FindItemFromCharacter(whichItemName, whichPlayer)
local charItems = whichPlayer.Character:GetChildren()
for _, eachItem in pairs(charItems) do
if eachItem.Name == whichItemName then
return eachItem
end
end
end
local function DestroyTool(whichTool, whichPlayer)
local toolInBackpack= FindItemFromBackpack(tool.Name, player)
if toolInBackpack then
toolInBackpack:Destroy()
toolInBackpack = nil
end
local toolInChar = FindItemFromCharacter(tool.Name, player)
if toolInChar then
toolInChar:Destroy()
toolInChar = nil
end
end
ReplicatedStorage.ShopFunctions:WaitForChild("Ninjago").OnServerInvoke = function(player)
local myDebounce = true
if player.leaderstats.Money.Value >= 500 and MyDebounce == true and player then
MyDebounce = false
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 500
DestroyTool(tool, player)
end
end
Let me know how it goes.
2 comments
I’m sure this will help, i’ll check it tomorrow when I get back on. Thank you so much :)
Any updates on how it went? Don't forget to mark question as answered if this answers your question :P