Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Delete previous, or all weapons after buying another one?

THIS IS A REPOST, BECAUSE I GOT A CONFUSING ANSWER ON THE FIRST ONE LIKE 3 DAYS AGO


title might be confusing but, i'm making a button that gives you a weapon on a certain level, but to avoid taking up room in the backpack, i need it to delete the previous gear, or all gears before placing the new gear down, the thing i really need help with is how to get all the tools in the players backpack, i don't really know how to define that.

Here is my current Script

Points = 10 
Stat = "Points" 



Give = script.Parent
Backup = Give:Clone()

function onTouched(hit)
	if hit.Parent.Humanoid~= nil then
		local Plr = game.Players:findFirstChild(hit.Parent.Name)
		if Plr ~= nil then
			local StatLocal = Plr.leaderstats:findFirstChild(Stat)
			if StatLocal ~= nil then
				if StatLocal.Value >= Points then
					local Check = Plr.StarterGear:findFirstChild(script.Parent.Name)
					if Check == nil then
						StatLocal.Value = StatLocal.Value - Points
						
						
						local W1 = Backup:Clone()
						local W2 = Backup:Clone()
						W1.Parent = Plr.Backpack
						W2.Parent = Plr.StarterGear
					end
				end
			end
		end
	end
end
script.Parent.Parent.Touched:connect(onTouched)

this script does the job of putting the weapon in your backpack AND Starterpack, so if you die, you'll get the weapon back

Hey SteamDemand, Please don't make this extremely confusing :C

1 answer

✓ Accepted answer

Delete everything from the backpack or 1 item... I'll just show you what to do to delete everything:

localscript:

for _, v in pairs(game.Players.LocalPlayer.BackPack:GetChildren()) do
	v:Destroy()
end

bam immedietly gone from the backpack, another thing to note is that this has to be placed right before the part where you clone the item into the players backpack.

Ask me questions if you want to. Loop + :Destroy()

1 comment

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.