So my game was working fine, including all saving and loading of data into a Data Store, until the exact moment I had a successful POST from HttpService to my website’s database. Since then, my data modules are loading the player data from the Data store, but the data is always completely nil. My code initializes with default data like it’s supposed to, and then when the player leaves data is saved back to the Data Store. There are NO errors with either read or write operations, but even after the data is saved back the next time I load it in the data is nil again.
I have tried printing the data out immediately after it is loaded: nil, again after initializing it: correct values, before and after saving back to the data store: correct values. I even changed the name of the Data Store to try a completely fresh one with no difference.
I don’t know how HttpService could really be interfering with it, but it would be a really huge coincidence otherwise and I have no other explanation. Here is my code for loading from data store (as bits taken from the entire module):
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerStats")
local data = {}
local count = 0
while not success and count < 4 do
count += 1
success, err = pcall(function()
print("Fetching data for "..newPlayer.userId)
data = PlayerData:GetAsync(newPlayer.userId)
end)
if not success then
warn(err..": DataStore load failed. Retrying in 5.")
wait(5)
end
end
Again, this code does not error.
local staleData = false
if data then
if data["lastLogin"] then
print("Last login on "..getDate(DateTime.fromUnixTimestamp(data["lastLogin"])))
if data["lastLogin"] < resetTime then
print("Old data detected, resetting data...")
staleData = true
end
else
print("Last login not found!")
data["lastLogin"] = DateTime.now().UnixTimestamp
end
else
print("First login detected!")
end
if not data or staleData or dataReset then
print("No player data found, creating new data...")
data = {
["lastLogin"] = DateTime.now().UnixTimestamp,
["level"] = 1,
["exp"] = 0,
["next"] = 25,
["coins"] = 500,
["gems"] = 0,
["equipped"] = {"Scout Post", "Wooden Wall", "Empty", "Empty", "Empty"},
["boardMaxX"] = 16,
["boardMaxY"] = 16,
["boardType"] = "Grass",
["towersInv"] = defaultTowers,
["boardsInv"] = defaultBoards
}
end
This code always reports a first login, even after successfully saving and re-loading the data.
And to be complete, here is the code I have for my HttpService:
local HttpService = game:GetService("HttpService")
success, err = pcall(function()
local response = HttpService:RequestAsync({
Url = "--[[address hidden]]",
Method = "POST",
Body = message
})
if response.Success then
print("Status code: ", response.StatusCode, response.StatusMessage)
print("Response body: ", response.Body)
else
print("Request failed: ", response.StatusCode, response.StatusMessage)
end
end)
Again, the code is working fine for this. Here’s the results on my database:
I’ve tried commenting out the http code: no change.
I’ve tried disabling the http access in game settings: no change.
At this point I have absolutely no idea what is wrong or why this is happening, and no clue how to fix it.
Does anyone have an idea?