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

Why does this backpack script not work?

This script is to basically clone the player's backpack into game.Lighting.Game_Tools then clear the player's backpack, wait about 10 seconds, and give the player's backpack back.

tools = {"AK14", "Pistol", "Shotgun"}
player = game.Players.LocalPlayer
for a,b in pairs(game.Players:GetPlayers()) do 
    for i,v in pairs(b.Character:GetChildren()) do 
        if v:IsA("Tool") then 
            k =  player.Backpack:Clone().Parent = game.Lighting.Game_Tools
b.Backpack:ClearAllChildren()
wait(10
for i = 1,#tools do
 game.Lighting.Game_Tools:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
 game.Lighting.Game_Tools:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
 game.Lighting.Game_Tools:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
 game.Lighting.Game_Tools:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
        end
    end
end

Any help please?

1 answer

First you'll need to put it in a server script in the workspace or what ever you want but not in the player.

We'll make it a little more clean before and fix your error, I mean put the ends where you forgot to put it.

Second, we'll add theses events for make your Game_Tools more cleaner and we'll do for when the player leave the folder get destroy, without that you can get so many folder when the player left and It can make it glitch.

After, we'll create the main function and put the body in.

Finally, we run the function with a loop for while 60 secondes your function will run.

--local tools = {"AK14", "Pistol", "Shotgun"}--I don't know what you want to do with that so I comment it.
local newParent = game.Lighting["Game_Tools"]

game.Players.PlayerAdded:connect(function(player)
	local playerSlot = Instance.new("Folder", newParent)
	playerSlot.Name = player.Name
end)

game.Players.PlayerRemoving:connect(function(player)
	local playerSlot = newParent:FindFirstChild(player.Name)
	if playerSlot then
		playerSlot:remove()
	end
end)

function main()
	for _, player in pairs(game.Players:GetPlayers()) do
		local backpack = player:WaitForChild("Backpack")
		for _, tool in pairs(backpack:GetChildren()) do
			if tool:IsA("Tool") or tool:IsA("HopperBin") then
				tool.Parent = newParent
			end
		end
	end
	
	wait(10)
	
	for _, playerSlot in pairs(newParent:GetChildren()) do
		local player = game.Players:FindFirstChild(playerSlot.Name)
		if player then
			local backpack = player:WaitForChild("Backpack")
			for _, tool in pairs(playerSlot:GetChildren()) do
				tool.Parent = backpack
			end
		end
	end
end

while true do
	wait(60) --Wait 60 secondes before run the function
	main()
end

enjoy !

11 comments

0

There was an error saying PlayerRemoved is not a valid member of Players

0

o wait

0

Now it should work I fix it.

0

Ok ill try it now

0

Nope, It's not removing any tools from the player :/

0

You need to wait 60 secondes xD but you can change 60 secondes for another number http://prntscr.com/87ny8r

0

Yeah I changed it to 5 and nothing happened

0

Do you have tools in your backpack?

0

did you put in a server script in the workspace ?

0

nvm Ik why..

0

Now It supposed to work.

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