Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Does This Script For Retrieving DataStore Values Not Print Anything?

This script that I have made is supposed to filter through 7 values in the player's storage and determine which of them are true (one out of seven will always be true). However, when this script is activated, absolutely nothing happens; nothing is printed other than the first one, "loading." This really is frustrating me. Why won't it do anything?

game.Players.PlayerAdded:connect(function(player)
	print("loading") --The only thing that actually prints.
	wait(3)
	local DataStore = game:GetService("DataStoreService"):GetDataStore("lorStore")
	local text = player.PlayerGui.Tutorial.SaveNumber
	local key = "user-" ..player.UserId.. "-lastSlot" --The key.
	local savedValues = DataStore:GetAsync(key)
	if savedValues ~= nil then
		local values = {savedValues[1], savedValues[2], savedValues[3], savedValues[4], savedValues[5], savedValues[6], savedValues[7]}
		for i, v in pairs(values) do
			if v == true then
				print("loaded")
				text.Text = i --Whichever value is true, the number is put on the GUI.
			else
				print("nil")
				text.Text = "error"
			end
		end
	else
		print("key doesn't exist")
	end
end)

Thank you for helping out! It means a lot!

6 comments

0

the datastore should be on line 1 before anything else.. just tested it and it prints "key doesnt exist" in my script test server. with datastore before the function and after so idk why it doesnt work for you

0

Thanks; I updated it, but the script still isn't working.

0

hmm thats weird. it works for me in studio and regular server. is there any output?

0

The only output is that it prints ("loading")

0

I honestly can't debug unless you can give me a link to a screenshot of the Dev gui(F9) Because I can't see any errors.

1 answer

✓ Accepted answer

all i did was change the data store but i tested both ways and it worked for me.

and the numbers in the datastore is a precaution in case so no can use the datastore as you

local DataStore = game:GetService("DataStoreService"):GetDataStore("lorStore34315262352352634426135") 

game.Players.PlayerAdded:connect(function(player)
    print("loading") --The only thing that actually prints.
    wait(3)

    
    local text = player.PlayerGui.Tutorial.SaveNumber
    local key = "user-" ..player.UserId.. "-lastSlot" --The key.
    local savedValues = DataStore:GetAsync(key)
    if savedValues ~= nil then
        local values = {savedValues[1], savedValues[2], savedValues[3], savedValues[4], savedValues[5], savedValues[6], savedValues[7]}
        for i, v in pairs(values) do
            if v == true then
                print("loaded")
                text.Text = i --Whichever value is true, the number is put on the GUI.
            else
                print("nil")
                text.Text = "error"
            end
        end
    else
        print("key doesn't exist")
    end
end)

11 comments

0

I tried this and it actually worked when I tested it in Studio, but when I tested it by publishing it to an actual game and visiting it, it didn't work...

0

oh. are you in the server log of the dev console? thats where it shows

0

When I checked it, it said Content Failed Because HTTP 404 (HTTP/1.1 404 Not Found)

0

thats very strange. of course it's happened to me. a data store refused to make stats for a game i was helping a friend edit but it worked on mine

0

mine said that too. but it still print Key doesnt exist after it https://i.gyazo.com/616baa5b2a387882d39d5588a23ce924.png

0

What do you recommend I should do?

0

try seeing if it will work on a new server.

0

Still nothing.

0

It seems to be happening because of the "GetAsync" line, as I decided to put the "print("loading")" line right before it and when I tested the game, everything worked until after it printed "loading."

0

id like to help more but i dont see where you got what it's saving from the script. it's just telling me "key doesn't exist"

0

i got this(nil) ( 21:57:18.233 - Workspace.Script:15: attempt to index local 'savedValues' (a nil value)) by changing line 11 to this. idk if it will help you but (if savedValues == nil then print(savedValues)) the ~= was changed to ==

This discussion is preserved as it was. New answers, comments, and votes are closed.