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

Is it possible to limit your inventory?

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?

4 comments

0

You can remove the default backpack with “StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)” and make your own

0

It's not necessary to make an entire inventory on your own.

0

Only a few lines of code are really needed to allow only one item

0

Destroy the item in backpack -> add the new item

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.