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?
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)
There, that's much cleaner AND filteringEnabled for free!
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)
Good Luck with your games!