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

How do i get my Data saving script to give weapons to a player after they died?

Asked by 6 years ago
local datastore = game:GetService("DataStoreService")

local ds1 = datastore:GetDataStore("Inventory")


game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(character)

        local Items = ds1:GetAsync(plr.userId)
        if Items ~= nil then
            for i,v in pairs(Items) do
                if game.ServerStorage.Tools:FindFirstChild(v) ~= nil then
                    local Tool = game.ServerStorage.Tools:FindFirstChild(v)
                    Tool.Parent = plr.Backpack
                end
            end
        end     


    end)    

end)


game.Players.PlayerRemoving:connect(function(plr)
    local Table = {}
    for i,v in pairs (plr.Backpack:GetChildren()) do
        table.insert(Table,v.Name)
    end
    if Table ~= nil then
        ds1:SetAsync(plr.userId,Table)
    end



end)

1 answer

Log in to vote
0
Answered by 6 years ago

You need to put the tool into StarterGear also

0
This script does work and loads up tools when i re-join however doesn't dispense the tools if the player dies NoirPhoenix 148 — 6y
Ad

Answer this question