Still have questions? Join our Discord server and get real time help.
0

# Destroying item from players backpack not working? [HELP PLEASE]

JellyYn 70
2 years ago
local apple = script.Parent
local p = game.Players.LocalPlayer
apple.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
p.Backpack:WaitForChild("Apple"):Destroy()
end)
end)


I have it so the apple's parent turns in to the players Backpack when clicked from the workspace. I want it to when you click, it removes it from the players Backpack for good. Any ideas on how to fix this?

1
Nonaz_jr 439
2 years ago
Edited 2 years ago

Hi, as Leamir points out the item when equiped is in the character, not the backpack. So as explained in his answer and the comments either check there instead or unequip the item before looking for it in backpack and destroying it.

I would like to add that your script is not FilteringEnabled compatible: You cannot destroy items from a localscript. However, to fix it is easy, as you do not actually need to listen to the mouseclick but can instead use apple.Activated (which triggers on mouseclick while equiped serverside.

Also despite my extensive comments to make sure you find the apple in the right place and it exists, just use script.Parent:Destroy()

X) i wasn't thinking ;)

so move the code to a script (not a localscript any more) and make it:

local apple = script.Parent
apple.Activated:Connect(function()
apple:Destroy()
end)


1
Leamir 2963
2 years ago
Edited 2 years ago

Hello, JellyYn!

Your script don't works because when player equips an item, its goes to its character(game.Players.LocalPlayer.Character), so you have to get its character in workspace, like I did!

local apple = script.Parent
local p = game.Players.LocalPlayer
apple.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
game.Workspace[p.Name][apple.Name]:Destroy()
end)
end)



1
You forgot to do [apple.Name] User#19524 170 — 2y
0
solving... and thanks Leamir 2963 — 2y
0
It works! The only thing I had to change for it to work (for me, at least, with FE on), was [apple]. I had to change it to [p.name]:WaitForChild("Apple"):Destroy() and it worked. I will accept this answer anyway because it helped a lot. JellyYn 70 — 2y
0
You can just use '[p.name]:FindFirstChild("Apple"):Destroy()' This don't will break your script if player don't have the item(ik, its a little impossible, but) Leamir 2963 — 2y