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

Tool Auto-Saving Script not working? I believe the "StarterGear" has something to do with it?

Asked by 8 years ago
function saveWeapons(player)
    local bin = Instance.new("StarterGear") --Changed HopperBin to StarterGear
    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)

The tools still will not auto-save. Anyone know why this is? If anyone knows a auto-save script model already made would they be able to tell me if so? This has been bugging me for a long time and I still cannot figure it out.

0
Why don't you just add the tool to the players startergear when they get it then make a debouncer so it won't add multiple versions of it. Meltdown81 309 — 8y
0
I get what you are saying, I just don't understand how to do it. Would there be any help on the issue of "me not knowing how to do it?" Neodyne 0 — 8y

Answer this question