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

How do I fix my auto tool saving system?

Asked by 8 years ago
Edited 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)

I get this error.

11:04:59.910 - Workspace.SaveWeapons:32: attempt to index field 'Character' (a nil value)
11:04:59.912 - Stack Begin
11:04:59.913 - Script 'Workspace.SaveWeapons', Line 32 - global onRespawned
11:04:59.914 - Script 'Workspace.SaveWeapons', Line 40
11:04:59.916 - Stack End
0
Question, you do know if you put the item in player.startergear it'll automatically save, at least in that server right? Kitorari 266 — 8y
0
Yes Neodyne 0 — 8y
0
So I save all of the weapons to the players player.startergear? Neodyne 0 — 8y
0
hopperbins are deprecated, character doesn't exist, use startergear DepressionSensei 315 — 8y
0
So is the new script good? Neodyne 0 — 8y

Answer this question