I have a GUI and an image button that is once pressed, it will give the player a "Shotgun" and a "Pistol", So the players don't abuse it and get infinite guns, How could I Make it so that it clears the player's backpack completely and then gives the player the two guns, I can't just say tool:destroy() because there are multiple guns in the game like an AK and a sniper so it wouldn't be convenient to do a tool:destroy() for every gun in the game anyways here's the code

script.Parent.MouseButton1Click:Connect(function() --Click detector
	game.ReplicatedStorage.Shotguns.Shotgun:Clone().Parent =
	 game.Players.LocalPlayer.Backpack --Shotgun Giver
	game.ReplicatedStorage.Pistols.Pistol3:Clone().Parent =
	 game.Players.LocalPlayer.Backpack --Pistol Giver
	script.Parent.Parent.Visible = false --Sets the frame status to invisble
	game.SoundService.Barret_Equip.Playing = true --Plays reload sound effect
end) --Note this is a *local script*

Please if you're willing to help edit this code above with explanation Sorry if I am asking too much

6 comments

0

Well, maybe you could put all the weapons into a table, make the table a variable, and just clear the table?

0

Well I guess I could do that, but It would be really difficult to change some stuff in the future

0

The tools shouldn't even work since they are only being put in the backpack by the clients and not the server.

0

No, The tools actually work?????

0

Add local weapon1 = gun:Clone(). weapon1.Parent = game.Players.LocalPlayer.Backpack. Later, you can do weapon1:Destroy()

0

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