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

How to insert and remove items from all players inventories?

I am making a game where you should only be able to have certain items at certain times. How do i complete this?

1 answer

Hi there! If you are wanting to remove every player's items on a game, you would have to use a for loop, which would loop through

game.Players:GetChildren()--This returns a table of ALL the players in the game

Here is an example script for removing all of the players items:

local players = game.Players:GetPlayers()
for i,v in pairs(players) do--the variable "v" is equal to the target player
	v.Backpack:ClearAllChildren()--This removes everything in the targetted players backpack
end

To give everyone an item, you would need to define the object you want to give, and then use a for loop again:

local players = game.Players:GetPlayers()
local object = definethis
for i,v in pairs(players) do
	local newObj = object:Clone()
	newObj.Parent = v.Backpack
end

Hope this helped!

3 comments

0

^ Wrong. You don't need he extra parenthises after "players". I am talking about in the "pairs()".

0

How do i insert an existing item from lighting into a players inventory

0

Oh yeah, my bad FiredDusk ;p

This discussion is preserved as it was. New answers, comments, and votes are closed.