I am trying to make a data store for my Roblox game. I am not so familiar with data stores, so I had lots of issues.
When I run the data store, I get the error of:
13:05:56.235 - ServerScriptService.DataStoreManager:28: invalid argument #3 (string expected, got nil)
I have nothing to save, that is why it is nil. I tried to solve that by writing if statements to replace the value with a number instead of nil, but that failed, too. I have tried going onto discord and asking others, I got no help from them. (all they said was "this isn’t how you should write a datastore at all!11!! like dude that isnt helping me just help me solve this) I went onto the developer wiki, doesn’t exactly answer my question. Now, I am here.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("StoreData")
game.Players.PlayerAdded:Connect(function(Player)
local Data = Instance.new("Folder")
Data.Parent = Player
Data.Name = "PlrData"
local CoinsValue = Instance.new("StringValue")
CoinsValue.Parent = Player.PlrData
CoinsValue.Name = "Coins"
local GemsValue = Instance.new("StringValue")
GemsValue.Parent = Player.PlrData
GemsValue.Name = "Gems"
local success, notsuccess = pcall(function()
Gems = DataStore:GetAsync(GemsValue.Value.." - Gems")
Coins = DataStore:GetAsync(CoinsValue.Value.." - Coins")
if Gems and Coins == nil then
DataStore:SetAsync(Player.AppeareanceId, CoinsValue.Value == 75)
DataStore:SetAsync(Player.AppeareanceId, GemsValue.Value == 5)
end
end)
if success then
GemsValue.Value = Gems
CoinsValue.Value = Coins
print(Player.Name.."'s data has successfully been loaded upon entry")
else
print("An error has occured while loading "..Player.Name.."'s data")
error(notsuccess)
end
end)
If you can help me, please reply to this post. Thank you so much!