Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this backpack script not work?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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 !

0
There was an error saying PlayerRemoved is not a valid member of Players KeepTheChange50Cent 0 — 8y
0
o wait XToonLinkX123 580 — 8y
0
Now it should work I fix it. XToonLinkX123 580 — 8y
0
Ok ill try it now KeepTheChange50Cent 0 — 8y
View all comments (7 more)
0
Nope, It's not removing any tools from the player :/ KeepTheChange50Cent 0 — 8y
0
You need to wait 60 secondes xD but you can change 60 secondes for another number http://prntscr.com/87ny8r XToonLinkX123 580 — 8y
0
Yeah I changed it to 5 and nothing happened KeepTheChange50Cent 0 — 8y
0
Do you have tools in your backpack? XToonLinkX123 580 — 8y
0
did you put in a server script in the workspace ? XToonLinkX123 580 — 8y
0
nvm Ik why.. XToonLinkX123 580 — 8y
0
Now It supposed to work. XToonLinkX123 580 — 8y
Ad

Answer this question