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

[solved] DataStore for tools isn't working with no errors but printing things correctly, any help?

Asked by 3 years ago
Edited 3 years ago

I wanted to make a DataStore for tools. There are no errors whatsoever. Every number I print is printed in the output but the tools I was expecting isn't coming up.

local dss = game:GetService('DataStoreService')
local backpackds = dss:GetDataStore('BackpackStore')
local equipped = nil
game.Players.PlayerAdded:Connect(function(plr)
    local backpack = plr.Backpack
    local data = backpackds:GetAsync(plr.UserId)
    if data then
        for i, _ in pairs(backpack:GetChildren()) do
            _:Destroy()
        end
        print(0) 
        for i,_ in pairs(data) do
            print(12)
            if game.ReplicatedStorage:WaitForChild('Tools'):FindFirstChild(_) then
                print(1)
                local tool = game.ReplicatedStorage.Tools[_]
                local clonedver = tool:Clone()
                clonedver = backpack
                print(2)
            end
        end
    end 
    plr.CharacterAdded:Connect(function(c)
        c.ChildAdded:Connect(function(_)
            if _:IsA('Tool') then
                equipped = _
            end

        end)

    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)

    local backpack = plr.Backpack
    local data = {}
    for i, v in pairs(backpack:GetChildren()) do
        table.insert(data,v.Name)
    end 
    if equipped then

        table.insert(data,equipped.Name)

    end
    local success, msg = pcall(function()
        backpackds:SetAsync(plr.UserId,data)
    end)

    if not success then
        print('Error:',msg)
    else
        print('Saved Backpack for player',plr.Name)
    end
end)

I check the table in the DataStore plugin and it should've worked.

I deleted all tools since it was the starter tools.

I probably did something wrong getting the data but I don't know what...

Any suggestion/help is appreciated!

1 answer

Log in to vote
0
Answered by 3 years ago

dude, I DID CLONEDVAR = BACKPACK AND NOT CHANGE THE PARENT ;-;

Ad

Answer this question