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

This datastore not working? Invalid argument #3 string expected, got nil

Asked by
hokyboy 270 Moderation Voter
3 years ago
local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("AA99")

game.Players.PlayerAdded:Connect(function(player)

    local datafolder = Instance.new("Folder")
    datafolder.Name = "Data"
    datafolder.Parent = player

    local Grimoire = Instance.new("StringValue")
    Grimoire.Name = "Grimoire"
    Grimoire.Value = "FireGrimoire"
    Grimoire.Parent = datafolder 

    local data
    local sucess, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-Grimoire") -- error is in this line
    end)

    if sucess then
        Grimoire.Value = data
        print("Data loaded")
    else
        warn(errormessage)
    end
end)



game.Players.PlayerRemoving:Connect(function(player)
    local sucess, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-Grimoire",player.Data.Grimoire.Value)
    end)
    if sucess then
        warn("Data saved")
    else
        print("Error Saving Data") -- minor spelling mistake
        warn(errormessage)
    end
end)
0
a string was expected in argument #3 but you gave it nil? RAFA1608 543 — 3y

Answer this question