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

[SOLVED] My datastore doesnt work for some reason? Pcall keeps finding an error

Asked by 2 years ago
Edited 2 years ago

I'm making a leaderboard for the amount of robux someone has donated to my game but there is an error. The pcall keeps going to errormessage for some reason. If the solution is easy, pls don't roast me, I'm still trying to learn data stores. If you have any questions, feel free to ask!

local Dataservice = game:GetService("DataStoreService")
local DonationStats = Dataservice:GetChildren("DonationStats")


game.Players.PlayerAdded:Connect(function(plr)
    local Leaderstats = Instance.new("Folder", plr)
    Leaderstats.Name = "leaderstats"

    local Dono = Instance.new("IntValue", Leaderstats)
    Dono.Name = "Donation"

    local plrId = "Player_"..plr.UserId

    local data

    local success, errormessage = pcall(function()
         data = DonationStats:GetAsync(plrId)
    end)

    if success then
        Dono.Value = data
    end

end)


game.Players.PlayerRemoving:Connect(function(Removed)
    local PlrId = "Player_"..Removed.UserId

    local data = Removed.leaderstats.Donation

    local success, errormessage = pcall(function()
        DonationStats:SetAsync(PlrId, data.Value)
    end)

    if success then
        print("Saved data for"..Removed.Name)
    end

    if errormessage then
        print("Data Save had an error for"..Removed.Name)
        print(data.Value)
    end

end)

1 answer

Log in to vote
0
Answered by 2 years ago

The key and string were backwards

Ad

Answer this question