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

Why isn't my tool loading? And nothing is printing when i use GetAsync

Asked by 5 years ago
Edited 5 years ago

code:

local DataStore = game:GetService("DataStoreService")
local SaveTools = DataStore:GetDataStore('Save_Tools')
----
game.Players.PlayerAdded:Connect(function(player)
    local tools = player:WaitForChild('Backpack')
    for i,v in pairs(tools:GetChildren()) do
    local data = v
    local success, errormessage = pcall(function()
        SaveTools:GetAsync(player.UserId..'-Tools')
    end)
    if success then
        print('Loading tools')
        local Curr_Tools = data:Clone()
        Curr_Tools.Parent = player.Backpack
    if not success then
        print('Oh no, A error occured!')
        warn(errormessage)
end
    end
    end
    end)
0
This doesn't make sense. You're getting tools from the players backpack and upon a successful return of loaded data, you're re-parenting those same tool to their Backpack. Azarth 3141 — 5y
0
But why isn't it printing though? Freddan2006YT 88 — 5y
0
When it succseded Freddan2006YT 88 — 5y
0
You have not success in the success scope, so it's not going to print. Azarth 3141 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
    local DataStore = game:GetService("DataStoreService")
    local SaveTools = DataStore:GetDataStore('Save_Tools')
    ----

    local errormessage = "An error has occured!"

    game.Players.PlayerAdded:Connect(function(player)
        local tools = player:WaitForChild('Backpack')
        for i,v in pairs(tools:GetChildren()) do
        local data = v
        local success, errormessage = pcall(function()
            SaveTools:GetAsync(player.UserId..'-Tools')
        end)
        if success then
            print('Loading tools')
            local Curr_Tools = data:Clone()
            Curr_Tools.Parent = player.Backpack
        if not success then
            print('Oh no, A error occured!')
            warn(errormessage)
    end
        end
        end
        end)

You forgot to put "Local errormessage = "An error has occurred!" "

Let me know if this works.

0
Error message should be what went wrong in the pcall it shouldnt be a string. Freddan2006YT 88 — 5y
Ad

Answer this question