I was creating a script for loading a player's values from a DataStore by the click of a button, but when testing it in an actual Roblox game and checking the server log in the developer console, an error occurred saying what the title says. I have no clue at all what it means or how to fix it. The script I made works perfectly in the Roblox Studio Server but not in the actual Roblox game.
The best I've been able to discover is that it is most likely due to the "GetAsync" function. From my research on the Wiki, I've discovered that it has the potential to error, from long keys to bad Internet connections. I've checked everything and they all seem to be perfectly in order, yet this continues to happen. Does anybody know how I can fix this or if there is a different way to script this in order to get around this issue?
This is my script.
local DataStore = game:GetService("DataStoreService"):GetDataStore("12345674587345") --Retrieving the DataStore. script.Parent.MouseButton1Up:connect(function() --When clicked, activate this function. local player = script.Parent.Parent.Parent.Parent --Identifying the player. local text = player.PlayerGui.Tutorial.SaveNumber --This is supposed to display a number that was chosen by the player from 1 to 7. local key = "user-" ..player.UserId.. "-lastSlot" --Player's key. local savedValues = DataStore:GetAsync(key) --Getting the player's data from the DataStore. text.Text = "loading" --The purpose of this was to just see if it worked after GetAsync. wait(1) if savedValues then local values = {savedValues[1], savedValues[2], savedValues[3], savedValues[4], savedValues[5], savedValues[6], savedValues[7]} --Creating a table of the 7 values to use it for an In Pairs function. for i, v in pairs(values) do if v == true then --Whatever number was true, that number is displayed in the aforementioned textlabel. print("loaded") text.Text = i else print("nil") --If none of them are true for some reason, it'll show an error. text.Text = "error" end end else print("no key found") --If there's no key, it'll do this. end end)
It's an error telling you that something is missing / the link is wrong