How to replace an item instead of destroy it? (video + script)

does this one also not respond to the brown part?

-- localscript inside starterplayerscripts
while true do
    task.wait(1)
    print(#game.Players.LocalPlayer.Backpack:GetChildren())
end
1 Like

My bad : I made a mistake in my previous answer (hence my deletion) I test and I tell you

Now both parts react correctly, however they react only once each. The output is similar
1 then 1(x2) then 1(x3)…
and i click on the other part
2 then 2(x2) then 2(x3)…
from there I can’t do anything.

strange are you placing the brown part into the backback with a localscript or the same as the green part?

1 Like

no script in severstorage
Capture

and I disabled all the scripts linked to it except these ones

i think the giver should look like this

script.Parent.ClickDectector.MouseClick:Connect(function(player)
    game.ServerStorage.Wrench3:Clone().Parent = player.Backpack
end)

because your giver code will take the tool from 1 player and give it to another player when they click the giver

but i’m still not sure why my first script i showed you never worked

when i get some time ill see if i can make a demo project

1 Like


I try your old scripts with these new scripts and I tell you

If I make a small demo project would you prefer the tool gets instantly equipped and bypass the inventory all together or do you like it going into the backpack?

1 Like

I don’t differentiate well between the concepts of backpack and inventory. But in other words, I would like the new item1 to replace the old item2 (and the item2 is not active anymore) but the player can always take the old item2 (in which case the new item1 is not active anymore) and so on.

Thank you very much!

The solution was written on the topic by TSL and it worked thanks to your help with theses new scripts. Thank you very much! Edit: Thanks again for all the time you gave me

Thanks a lot it worked perfectly

lol, I posted that 2h ago, glad it works though

OK i finally had a chance to open Roblox studio

here is the demo project
Backpack.rbxl (34.5 KB)

and this is the main script in the demo

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- when a tool is equiped empty backpack
		character.ChildAdded:Connect(function(child)
			if child:IsA("Tool") == false then return end
			for i, child in ipairs(player.Backpack:GetChildren()) do
				child.Handle.CFrame = character.PrimaryPart.CFrame + character.PrimaryPart.CFrame.LookVector * 10
				child.Parent = game.Workspace
			end
		end)
		-- when a item is added to the backpack remove all old items
		player.Backpack.ChildAdded:Connect(function(addedChild)
			for i, child in ipairs(player.Backpack:GetChildren()) do
				if child == addedChild then continue end
				child.Handle.CFrame = character.PrimaryPart.CFrame + character.PrimaryPart.CFrame.LookVector * 10
				child.Parent = game.Workspace
			end
		end)
	end)
end)
1 Like

Thank you very much i appreciate it