Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a gui button that clears your inventory, I've tried so much?

Asked by 2 years ago

Please be more describing, I'm quite new to lua/

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Put this inside your button:

local Button = script.Parent

Button.MouseButton1Down:Connect(function() -- Detect when the player click the button
   game.ReplicatedStorage.ClearInventory:FireServer()
end)

now create a new RemoteEvent in ReplicatedStorage and name it "ClearInventory"

now put this inside ServerScriptStorage:

game.ReplicatedStorage.ClearInventory.OnServerEvent:Connect(function(player) -- Detect when a player fire the RemoteEvent
   for _,i in pairs(player.Backpack:GetChildren()) do -- Loop inside the player's inventory
     i:Destroy() -- Destroy the item
   end
end)
Ad

Answer this question