I've recently been working on DataStores, and making them more efficient. The script creates the values, but doesn't fill in the values. This is in a script, in ServerScriptService. Nothing is put in the output, and it randomly chooses to fill in some values, but doesn't fill them in on other values. What did I do wrong?

local Appearance_1 = game:GetService('DataStoreService'):GetDataStore('Appearance_2')

  

local prefix = 'user_'

  

  

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

local folder = Instance.new('Folder',player)

folder.Name = 'Players_Outfit'

local CompletedBasic = Instance.new('BoolValue',folder)

CompletedBasic.Name = 'CompletedBasic'

local Face = Instance.new('IntValue',folder)

Face.Name = 'Face'

  

local Hair = Instance.new('IntValue',folder)

Hair.Name = 'Hair'

  

local Helmet = Instance.new('IntValue',folder)

Helmet.Name = 'Helmet'

  

local SkinColor = Instance.new('IntValue',folder)

SkinColor.Name = 'SkinColor'

  

local Shirt = Instance.new('IntValue',folder)

Shirt.Name = 'Shirt'

  

local Pants = Instance.new('IntValue',folder)

Pants.Name = 'Pants'

  

local plrData = Appearance_1:GetAsync(prefix .. tostring(player.UserId))

if plrData then

Face.Value = plrData[1] or 1

Hair.Value = plrData[2] or 1

Helmet.Value = plrData[3] or 1

SkinColor.Value = plrData[4] or 1

Shirt.Value = plrData[5] or 1

Pants.Value = plrData[6] or 1

CompletedBasic.Value = plrData[7] or false

else


  

Appearance_1:SetAsync(prefix .. tostring(player.UserId), {

Face.Value,

Hair.Value,

SkinColor.Value,

Shirt.Value,

Pants.Value,

CompletedBasic.Value,

})

end

  

end)

1 comment

0

Preset your values instead of using "or" in the GetAync portion of the script. If there is Data, it will write "nil" to any value for which "nil" was saved, regardless of you writing "or"