Remove item on death

I was trying to make items obtained through like shops to be removed after death by putting server script inside my tools
(heres the shop script i used)

local price = 100
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local clone = game.ReplicatedStorage:WaitForChild("M16"):Clone()

	if plr.leaderstats.Coin.Value >= price then
		plr.leaderstats.Coin.Value = plr.leaderstats.Coin.Value - price
		clone.Parent = plr.Backpack
		clone:Clone().Parent = plr.StarterGear
	end
end)

example)

but i couldnt get rid of items obtained through shop by putting

local Tool = script.Parent  
Char = Tool.Parent.Parent.Character 
function onDeath()
Tool:Destroy()
end
Char.Humanoid.Died:connect(onDeath)

so i tried like

        for i, v in pairs(Player.StarterGear:GetChildren()) do
            if v.Name == DestroyItem.Name then
                v:Destroy()
            end
        end

        for i, v in pairs(Player.Backpack:GetChildren()) do
            if v.Name == DestroyItem.Name then
                v:Destroy()
            end
        end
        
        for i, v in pairs(Player.Character:GetChildren()) do
            if v.Name == DestroyItem.Name then
                v:Destroy()
            end
        end

but it didnt worked either.

im so frustrated and i dont know what to try next.

3 Likes

By default in roblox, if tool is not in players starter gear, it will automaticcally dissappear on death, so the solution is, to remove a line of code where you put clone inside players starter gear

5 Likes

oh…i was trying to do it in a hard way…
thanks for the help

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.