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

I want my game to save your tools after someone leaves whats wrong with my script?

Asked by 4 years ago
function saveWeapons(player)
    local bin = Instance.new("HopperBin")
    bin.Parent = game.Lighting
    bin.Name = player.Name
    local stuff = player.Backpack:GetChildren()
    for i = 1,#stuff do
        local name = stuff[i].Name
        if game.StarterPack:findFirstChild(name)==nil then
            stuff[i]:Clone().Parent = bin
        end
    end
    local char = player.Character:GetChildren()
    for i = 1,#char do
        if char[i].className == "Tool" then
            local name = char[i].Name
            if game.StarterPack:findFirstChild(name)==nil then
                char[i]:Clone().Parent = bin
            end
        end
    end
end

function onRespawned(player)
    local findBin = game.Lighting:findFirstChild(player.Name)
    if findBin~=nil then
        local stuff = findBin:GetChildren()
        for i = 1,#stuff do
            stuff[i]:Clone().Parent = player.Backpack
        end
        findBin:Remove()
    end
    player.Character.Humanoid.Died:connect(function()
        saveWeapons(player)
    end)
end

function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onRespawned(newPlayer)
        end
    end)
    while true do
        if newPlayer.Character~=nil then break end
        wait()
    end
    newPlayer.Character.Humanoid.Died:connect(function()
        saveWeapons(newPlayer)
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)
0
you only ran one of the functions? Wiggles1305 49 — 4y

Answer this question