When I Join the game it keeps say this error
ServerScriptService.DataStorage.RankCreator:36: invalid argument #3 (string expected, got nil):
The error is occuring at line 36
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("DataStore")
local function saveData(plr)
local dataTable = plr.leaderstats("Rank").Value
local success, err = pcall(function()
dataStore:SetAsync(plr.UserId, dataTable) -- Save the data with the player UserId, and the table we wanna save
end)
if success then -- If the data has been saved
print("Data has been saved!")
else -- Else if the save failed
print("Data hasn't been saved!")
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local rank = Instance.new("StringValue")
rank.Parent = leaderstats
rank.Name = "Rank"
local data -- We will define the data here so we can use it later, this data is the table we saved
local success, err = pcall(function()
data = dataStore:GetAsync(plr.UserId) -- Get the data from the datastore
print("getting data...")
end)
if success then
rank.Value = data
else
print("The player has no data!")
end
rank.Changed:Connect(function()
print("rank changed")
end)
end)
game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
local success, err = pcall(function()
saveData(player) -- Save the data
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
end)

2 comments
Im pretty sure it defines data at line 31
But it's not a string, is it?