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)

6 comments
Can you post the full error message for me to read?
what line does the studio redirect you to? if you click on it.
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??
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?
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
also shirtID.Value = data or "" -- fixed the problem with the string expected got nil