i'm fairly new to datastores even though i understand the basics, and my datastore would save the intvalues as it should. but when i tried to make it save a stringvalue, it says:
invalid argument #3 (string expected, got nil)
here's the code:
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("dataStore")
game.Players.PlayerAdded:Connect(function(player)
local l = Instance.new("Folder")
l.Name = "leaderstats"
l.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = l
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = l
local swordType = Instance.new("StringValue")
swordType.Name = "SwordType"
swordType.Value = "ClassicSword"
swordType.Parent = player
local winsData, cashData, swordData
local success, errormessage = pcall(function()
winsData = dataStore:GetAsync(player.UserId.."-wins")
cashData = dataStore:GetAsync(player.UserId.."-cash")
swordData = dataStore:GetAsync(player.UserId.."-sword")
end)
if success then
wins.Value = winsData
cash.Value = cashData
swordType.Value = swordData
else
print("There was an error whilst getting data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall (function()
dataStore:SetAsync(player.UserId.."-wins",player.leaderstats.Wins.Value)
dataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
dataStore:SetAsync(player.UserId.."-swordType",player.SwordType.Value)
end)
if success then
print("Player data has been saved")
else
print("There was an error saving player data")
warn(errormessage)
end
end)
game:BindToClose(function()
wait(3)
end)
like i said, the wins and cash values are saved fine. but when i added the swordtype stuff, it came up with the error.
please could someone help?

2 comments
You should put the values in a table and save them like @danklua said. You'll get a warning in the output for too many requests
This might be wrong but you may want to look into this, It looks like its saving before any values have been saved, as it's saying there was no value to save.