I am making a game with someone and it's kinda an RPG and apoc thing. I want people to only be able to hold a single gun, how do I do that?
✓ ANSWER ACCEPTED
Is it possible to limit your inventory?
2 answers
✓ Accepted answer
What you can do is you can check whenever the player's backpack's children have changed, then go from there!
The "ChildAdded" event is perfect for checking if something has been added.
game.Players.PlayerAdded:Connect(function(player) -- when the player joins the game. "player" is the player
player:WaitForChild("BackPack").ChildAdded:Connect(function(object) --object being that new item added
if object.Name ~= "put the name of your gun here" then --if not the gun, then...
object:Destroy() --remove it!
end
end)
end)
Please leave an upvote if this helped you out! Comment if something was wrong
You have to attempt the coding before asking a question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
You can remove the default backpack with “StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)” and make your own
It's not necessary to make an entire inventory on your own.
Only a few lines of code are really needed to allow only one item
Destroy the item in backpack -> add the new item