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

string expected, got nil??

Asked by
Zoltra 4
4 years ago
local DataStoreService = game:GetService("DataStoreService")
local shirtData = DataStoreService:GetDataStore("shirtData")

game.Players.PlayerAdded:Connect(function(player)
    local clothesID = Instance.new("Folder")
    clothesID.Name = "clothesID"
    clothesID.Parent = player

    local shirtID = Instance.new("StringValue")
    shirtID.Name = "shirtID"
    shirtID.Parent = clothesID

    -- Load Data

    local data
    local success, errormessage = pcall(function()
        data = shirtData:GetAsync(player.UserId)
    end)

    if success then
        print ("Successfully loaded shirt data")
        shirtID.Value = data
    else
        print("Couldn't load shirt data")
        warn (errormessage)
    end

end)

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

    local success, errormessage = pcall(function()
        shirtData:SetAsync(player.UserId, player.clothesID.shirtID.Value)
    end)

    if success then
        print ("Player shirt data sucessfully saved!")
    else
        print ("Couldn't save shirt data")
        warn(errormessage)
    end


end)

So in-game the player's shirt template is saved as the value of the string "shirtID". Error I keep getting is invalid argument #3 (string expected, got nil)

0
Can you post the full error message for me to read? Warphi 51 — 4y
0
what line does the studio redirect you to? if you click on it. dibblydubblydoo 45 — 4y
0
It was line 22. Ok so someone told me to put shirtID.Value = data or '' ------ I don't get the error now but it's not saving?? Zoltra 4 — 4y
0
data, is not a string, so it cannot be inside the Value property inside StringValue. Could you perhaps tell us what you're trying to do with that bit? dibblydubblydoo 45 — 4y
View all comments (2 more)
0
I've got it to work now. The data was not saving, is what I thought. But I didn't have a script calling that data so I couldn't tell it was saving or not. The shirt's id in the string value was saving but I wasn't calling it to be equal to the shirt template when the player joins. :D Zoltra 4 — 4y
0
also shirtID.Value = data or "" -- fixed the problem with the string expected got nil Zoltra 4 — 4y

Answer this question