I have followed Alvin Blox’s and TheDevKing’s tutorial on data stores twice! I just can’t get it to work!
It keeps printing the ‘success’ message but it also throws an error:
21:58:34.841 - ServerScriptService.DataStore:54: invalid argument #3 (string expected, got nil)
This is due to the ‘data’ saved is somehow nil, and yes… API is enabled
Some extra info:
This is a speedrunning game and every level has a ‘Timer’ value, this is what I want to save.

Don’t worry about the rest…
Script
local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
--[ Add Player Info ]--
local playerFolder = Instance.new("Folder")
playerFolder.Name = tostring(player)
playerFolder.Parent = game.ServerStorage
local inLevel = Instance.new("BoolValue")
inLevel.Name = "InLevel"
inLevel.Parent = playerFolder
local inRun = Instance.new("BoolValue")
inRun.Name = "InRun"
inRun.Parent = playerFolder
local endPart = Instance.new("ObjectValue")
endPart.Name = "endPart"
endPart.Parent = playerFolder
local PersonalBests = Instance.new("Folder")
PersonalBests.Name = "PersonalBests"
PersonalBests.Parent = playerFolder
local levels = game.Workspace:FindFirstChild("TeleportService").WorldOne:GetChildren()
for _, level in pairs(levels) do
local newLevel = Instance.new("StringValue")
newLevel.Name = level.Name
newLevel.Parent = PersonalBests
end
local levelValues = PersonalBests:GetChildren()
for _, level in pairs(levelValues) do
local toVal = Instance.new("NumberValue")
toVal.Name = "NumberValue"
toVal.Value = 999999999
toVal.Parent = level
end
local playerUserId = "player_" .. player.UserId
local data
local success, err = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
print("SUCCESS!!")
PersonalBests.Level1.Value = data
else
print("Complete failiure! :(")
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_" .. player.UserId
local data = game.ServerStorage:FindFirstChild(player.Name).PersonalBests.Level1
print(data)
local success, err = pcall(function()
myDataStore:SetAsync(playerUserId, data.Value)
end)
if success then
print("Succesfuly saved!")
else
print("There was an error!")
warn(err)
end
end)