Hello there! I’m trying to learn how to save data with DataStoreService, and I’m using the official Roblox guide to help me get stared. I followed along with it step by step, only replacing the value with an integer value, however something in the code is preventing it from working. The value I wanted to be saved and printed is not printed, and instead it displays the error message “Argument 2 missing or nil”. Can anyone help? (and yes, I did enable Studio Access for API Services)
local dataStoreService = game:GetService("DataStoreService")
local storedValue = dataStoreService:GetDataStore("storedValue")
game.Players.PlayerRemoving:Connect(function(player)
local setSuccess, errorMessage = pcall(function()
storedValue:SetAsync(player.UserId, player.Gold.Value)
end)
if setSuccess then
print("Saved data")
end
if not setSuccess then
warn(errorMessage)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Parent = player
local data
local setSuccess, errorMessage = pcall(function()
data = storedValue:SetAsync(player.UserId)
end)
if setSuccess then
gold.Value = data
print(gold.Value)
end
if not setSuccess then
warn(errorMessage)
end
end)
Sorry if its a simple mistake I’m making, I have no idea what I’m doing.