error: ServerScriptService.Store:95: bad argument #3 to 'Value' (string expected, got nil)
Code:
local DataStore = game:GetService("DataStoreService") local Ds1 = DataStore:GetDataStore("Characters") game.Players.PlayerAdded:connect(function(Player) local Gstuff = Instance.new("Folder",Player) Gstuff.Name = "Gamestuff" local Chars = Instance.new("Folder",Gstuff) Chars.Name = "Characters" local Create = Instance.new("Folder",Chars) Create.Name = "Folder" local Hotbar = Instance.new("Folder",Chars) Hotbar.Name = "AbilityHotBar" local Energ = Instance.new("IntValue",Create) Energ.Name = "Energy" Energ.Value = 100 local NumChars = Instance.new("IntValue",Chars) NumChars.Name = "Number" local BodyColors = Instance.new("BrickColorValue",Create) BodyColors.Name = "BColors" BodyColors.Value = BrickColor.new("Brick yellow") local HairColor = Instance.new("BrickColorValue",Create) HairColor.Name = "HairColor" HairColor.Value = BrickColor.new("Buttermilk") local HairId = Instance.new("StringValue",Create) HairId.Name = "HairId" HairId.Value = "Bald" local Shirt = Instance.new("StringValue",Create) Shirt.Name = "Shirt" local Pants = Instance.new("StringValue",Create) Pants.Name = "Pants" local Face = Instance.new("StringValue",Create) Face.Name = "Face" Face.Value = "rbxassetid://167133081" local Gender = Instance.new("StringValue",Create) Gender.Name = "Gender" Gender.Value = "Male" local Class = Instance.new("StringValue",Create) Class.Name = "Class" Class.Value = "None" local Exp = Instance.new("IntValue",Create) Exp.Name = "Exp" Exp.Value = 0 local MaxExp = Instance.new("IntValue",Create) MaxExp.Name = "MaxExp" MaxExp.Value = 100 local Level = Instance.new("IntValue",Create) Level.Name = "Level" Level.Value = 0 local Zeni = Instance.new("IntValue",Create) Zeni.Name = "Zeni" Zeni.Value = 0 local AbilOne = Instance.new("StringValue",Hotbar) AbilOne.Name = "AbilityOne" AbilOne.Value = "None" local AbilTwo = Instance.new("StringValue",Hotbar) AbilTwo.Name = "AbilityTwo" AbilTwo.Value = "None" local AbilThree = Instance.new("StringValue",Hotbar) AbilThree.Name = "AbilityThree" AbilThree.Value = "None" local AbilFour = Instance.new("StringValue",Hotbar) AbilFour.Name = "AbilityFour" AbilFour.Value = "None" local AbilFive = Instance.new("StringValue",Hotbar) AbilFive.Name = "AbilityFive" AbilFive.Value = "None" local Emote = Instance.new("StringValue",Hotbar) Emote.Name = "Emote" Emote.Value = "None" local Item = Instance.new("StringValue",Hotbar) Item.Name = "Item" Item.Value = "None" local Amount = Instance.new("IntValue",Item) Amount.Name = "Amount" Amount.Value = 0 local key = "Player-"..Player.userId local SavedValues = Ds1:GetAsync(key) if SavedValues then --Save Format -- {BodyColors,HairColor,HairId,Shirt,Pants,Face,Gender,Class,Level,NumChars,Zeni,Exp} BodyColors.Value = BrickColor.new(SavedValues[1]) HairColor.Value = BrickColor.new(SavedValues[2]) HairId.Value = SavedValues[3] Shirt.Value = SavedValues[4] Pants.Value = SavedValues[5] Face.Value = SavedValues[6] Gender.Value = SavedValues[7] Class.Value = SavedValues[8] Level.Value = SavedValues[9] NumChars.Value = SavedValues[10] Zeni.Value = SavedValues[11] Exp.Value = SavedValues[12] MaxExp.Value = SavedValues[13] AbilOne.Value = SavedValues[14] AbilTwo.Value = SavedValues[15] AbilThree.Value = SavedValues[16] AbilFour.Value = SavedValues[17] AbilFive.Value = SavedValues[18] Item.Value = SavedValues[19] Emote.Value = SavedValues[20] Amount.Value = SavedValues[21] else local ValuesToSave = {BodyColors.Value.Name,HairColor.Value.Name,HairId.Value,Shirt.Value, Pants.Value,Face.Value,Gender.Value,Class.Value,Level.Value,NumChars.Value,Zeni.Value,Exp.Value, MaxExp.Value, AbilOne.Value, AbilTwo.Value, AbilThree.Value, AbilFour.Value, AbilFive.Value, Item.Value, Emote.Value, Amount.Value} Ds1:SetAsync(key, ValuesToSave) end end)
Your issue appears to be the SavedValue table not containing all the data you expect. You can fix that by using or
to provide 'default' alternatives:
if SavedValues then --Save Format -- {BodyColors,HairColor,HairId,Shirt,Pants,Face,Gender,Class,Level,NumChars,Zeni,Exp} BodyColors.Value = BrickColor.new(SavedValues[1]) HairColor.Value = BrickColor.new(SavedValues[2]) HairId.Value = SavedValues[3] or 0 Shirt.Value = SavedValues[4] or 0 Pants.Value = SavedValues[5] or 0 Face.Value = SavedValues[6] or 0 Gender.Value = SavedValues[7] or 0 Class.Value = SavedValues[8] or 0 Level.Value = SavedValues[9] or 0 NumChars.Value = SavedValues[10] or 0 Zeni.Value = SavedValues[11] or 0 Exp.Value = SavedValues[12] or 0 MaxExp.Value = SavedValues[13] or 0 AbilOne.Value = SavedValues[14] or 0 AbilTwo.Value = SavedValues[15] or 0 AbilThree.Value = SavedValues[16] or 0 AbilFour.Value = SavedValues[17] or 0 AbilFive.Value = SavedValues[18] or 0 Item.Value = SavedValues[19] or 0 Emote.Value = SavedValues[20] or 0 Amount.Value = SavedValues[21] or 0 else
I didn't look into the types of your Value objects, so that 0
will be converted to a string for your StringValues, which should have an empty string default instead of "0"
.