I have a GUI and an image button that is once pressed, it will give the player an "AR" 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 I have multiple guns in the game so it wouldn't be convenient to do a remove a gun for every single gun in the game here's the code
script.Parent.MouseButton1Click:Connect(function() --Click detector game.Lighting.AssualtRifles.AR:Clone().Parent = game.Players.LocalPlayer.Backpack --Ar Giver game.Lighting.Pistols.Pistol:Clone().Parent = game.Players.LocalPlayer.Backpack --Pistol Giver end)
Easy to do! No need to delete the tool and give them again! You can check if the player has the item equipped or in the backpack before parenting the tools into the player's backpack!
local Player = game.Players.LocalPlayer local BackPack = Player:WaitForChild("Backpack") script.Parent.MouseButton1Click:Connect(function() --Click detector if BackPack:FindFirstChild("AR") or BackPack:FindFirstChild("Pistol") then return -- Doesn't give the tool if it's in the backpack elseif Player.Character:FindFirstChild("AR") or Player.Character:FindFirstChild("Pistol") then return -- Doesn't give the tool if equipped end game.Lighting.AssualtRifles.AR:Clone().Parent = BackPack --Ar Giver game.Lighting.Pistols.Pistol:Clone().Parent = BackPack --Pistol Giver end)
Also store your tools in ReplicatedStorage and note that the tool will only show up to the player, not other players since it's local.
You can delete all tool by For i
loop (i think that is what it called):
local PlayerBackPack = -- Backpack for i,v in pairs(PlayerBackPack:GetChildren()) do v:Destroy() end