I am making a game where you should only be able to have certain items at certain times. How do i complete this?
COMMUNITY QUESTION
How to insert and remove items from all players inventories?
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
^ Wrong. You don't need he extra parenthises after "players". I am talking about in the "pairs()".
How do i insert an existing item from lighting into a players inventory
Oh yeah, my bad FiredDusk ;p