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

HOW TO REMOVE TOOL FROM PLAYER?

hi thank you for your time and help i really appreciate it i have a simple problem i want to remove all tools from all players and then give it back to them when i want here is my code for doing it

local items=game.StarterPack:GetChildren()
for ii,item in pairs(items) do
	item.Parent=ServerStorage:WaitForChild("itemholder") -- put's it into a model
end

but t didn't work thank you if u have any idea please answer it.

1 answer

✓ Accepted answer

The StarterPack is not the place where the Player's tools are stored, they move to the Player's Backpack after the game runs. To remove tools from all players, you can do this.

for _,player in pairs(game.Players:GetChildren()) do
	for _,tool in pairs(player.Backpack:GetChildren()) do
		tool.Parent = ServerStorage:FindFirstChild("itemholder") -- This way, the tools get mixed up with other players' tools.
	end
end

This way, the tools get mixed up and you won't be able to give them back later, to fix this, you can add this in a server script:

local holder = ServerStorage:WaitForChild("itemholder")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.New("Folder")
	folder.Name = player.Name
	folder.Parent = holder
end)

game.Players.PlayerRemoving:Connect(function(player)
	local folder = holder:FindFirstChild(player.Name)
	if folder then
		folder:Destroy()
	end
end)

So, Your final script to remove all the tools from the players would be

for _,player in pairs(game.Players:GetChildren()) do
	for _,tool in pairs(player.Backpack:GetChildren()) do
		tool.Parent = ServerStorage:FindFirstChild("itemholder"):FindFirstChild(player.Name) -- This way, the tools wont get mixed up with other players' tools.
	end
end

13 comments

0

thank u really but this line of code in the server script game.Players.PlayerAdded:Connect(function(player) local folder = Instance.New("Folder") folder.Name = player.Name folder.Parent = holder end) gives me serverScriptService.main:67: attempt to call a nil value

0

does itemholder exist in the serverstorage?

0

yes it does

0

but should i put the for _,player in pairs(game.Players:GetChildren()) do 2 for _,tool in pairs(player.Backpack:GetChildren()) do 3 tool.Parent = ServerStorage:FindFirstChild("itemholder"):FindFirstChild(player.Name) in local or server because i have put it into a server script

0

and when i play my game i can not open the server storage folder in explore is it a normal thing or does it mean that threre is nothing in it

0

try using replicatedstorage instead of serverstorage

0

ok thanks

0

thank you oilkas it worked really thank you

0

the tolls dissapear but it still shows the error is it a big deal

0

what is the error?

0

the same error erverScriptService.main:67: attempt to call a nil value thiis line local folder = Instance.New("Folder")

0

thats odd

0

maybe i should create the itemholder in my script

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