Tool isn't being cloned after destroyed?

  1. What do you want to achieve?
    The tool giver isn’t giving the player the tool after it’s been removed by the player’s inventory. I’d like to only remove the tool from the player’s backpack, not the entire game.

  2. What is the issue?
    Here’s a video link: Trash & Tool Issue on Vimeo
    So the proximityprompt is used to give the player the tool, but when the player recycles the tool, then when they go to use the tool giver again, the tool isn’t being given to them anymore.

  3. What solutions have you tried so far?
    I can’t figure out what the problem is… I’ve tried to see if the tool is destroyed within ServerStorage but I’m not able to see the items in ServerStorage when testing my game. There also isn’t anything on the DevForum that has been related to my specific question/issue (that I could find after searching for hours).

Screen Shot 2022-07-18 at 7.43.00 AM

local prp = script.Parent
local pizza = game.ServerStorage["Pupperoni Pizza"]

prp.Triggered:Connect(function(player)
	pizza:Clone()
	pizza.Parent = player.Backpack
	game.StarterPlayer["Pup Pizza"].Value = true
	prp.Enabled = false
	wait(20)
	prp.Enabled = true
	
	end)

Screen Shot 2022-07-18 at 7.44.53 AM

player = game.Players.LocalPlayer
backpack = player.Backpack

script.Parent.yes.MouseButton1Click:connect(function(clicked)
	if backpack then
		for _,v in ipairs(backpack:GetChildren()) do
			if v:IsA('Tool') then v:remove() end
		end
		script.Parent:TweenPosition(UDim2.new(0.5, -165, -1, 0), "In", "Back", 1)
	wait(1)
		script.Parent:Destroy()
	end
end)

script.Parent.no.MouseButton1Click:connect(function(clicked)
		script.Parent:TweenPosition(UDim2.new(0.5, -165, -1, 0), "In", "Back", 1)
	wait(1)
		script.Parent:Destroy()
end)

Please let me know if you need any more information or additional explanation, I truly appreciate your help!

use for loop also on player.Character

for _,v in pairs(player.Character:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end
player = game.Players.LocalPlayer
backpack = player.Backpack

script.Parent.yes.MouseButton1Click:connect(function(clicked)
	if backpack then
		for _,v in pairs(player.Character:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end
		script.Parent:TweenPosition(UDim2.new(0.5, -165, -1, 0), "In", "Back", 1)
	wait(1)
		script.Parent:Destroy()
	end
end)

script.Parent.no.MouseButton1Click:connect(function(clicked)
		script.Parent:TweenPosition(UDim2.new(0.5, -165, -1, 0), "In", "Back", 1)
	wait(1)
		script.Parent:Destroy()
end)

Would this be the correct way to do that?

EDIT: I’ve inserted this script; however, now it doesn’t remove the tool from the player’s inventory/backpack.

You have to check both the character for any equipped tools and the backpack for any unequipped tools. Also while cloning the pizza, you’re creating a copy whilst not doing anything with the copy. You’re giving the player the original pizza, not the copy.

How would I give the copy to the player instead of the original pizza & delete the copy from the player’s backpack?

Sorry for a late reply. When you’re using :Clone(), it returns a copy of the object, so you would have to do something like this.

local clone = pizza:Clone()

and then modify the clone as you wish.

1 Like