So it successfully loads, but all of my values are apparently nil.
I set it to change to a none if it was nil, mostly to test, but everytime I play test, it keeps staying as “nil” so it changes.
Here is my code:
local datastore = game:GetService("DataStoreService")
local actordatastore = datastore:GetDataStore("Profile")
local profiledata = {
["1"] = "None", -- description
["2"] = "No input", -- Gender
["3"] = "None", -- last played character
}
game.Players.PlayerAdded:Connect(function(plr)
local data
local success, errormessage = pcall(function()
data = actordatastore:GetAsync("actor-".. plr.UserId)
end)
if success then
if data[1] == nil then
print("Data 1 was nil, changing to No Input")
profiledata[1] = "None"
print(profiledata[1])
else
print("Loaded data1 - " .. data[1])
profiledata[1] = data[1]
end
if data[2] == nil then
print("Data 2 was nil, changing to No Input")
profiledata[2] = "No Input"
print(profiledata[2])
else
print("Loaded data2 - " .. data[2])
profiledata[2] = data[2]
end
if data[3] == nil then
print("Data 3 was nil, changing to No Input")
profiledata[3] = "None"
print(profiledata[3])
else
print("Loaded data3 - " .. data[3])
profiledata[3] = data[3]
end
else
warn(errormessage)
game:GetService("DataStoreService"):GetDataStore("Profile"):UpdateAsync("actor-".. plr.UserId, profiledata)
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player) -- Checking if player is leaving game
print(profiledata[1],profiledata[2],profiledata[3])
local Success, Error = pcall(function()
return game:GetService("DataStoreService"):GetDataStore("Profile"):UpdateAsync("actor-".. Player.UserId, profiledata[1],profiledata[2],profiledata[3])
end)
if Error then
warn(Error)
end
end)
Update, I found this weird message as well.