Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
8391ice 91
7 years ago
Edited 7 years ago

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!

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 RobloxianDestory 262 — 7y
0
Thanks; I updated it, but the script still isn't working. 8391ice 91 — 7y
0
hmm thats weird. it works for me in studio and regular server. is there any output? RobloxianDestory 262 — 7y
0
The only output is that it prints ("loading") 8391ice 91 — 7y
View all comments (2 more)
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. H4X0MSYT 536 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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)

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... 8391ice 91 — 7y
0
oh. are you in the server log of the dev console? thats where it shows RobloxianDestory 262 — 7y
0
When I checked it, it said Content Failed Because HTTP 404 (HTTP/1.1 404 Not Found) 8391ice 91 — 7y
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 RobloxianDestory 262 — 7y
View all comments (7 more)
0
mine said that too. but it still print Key doesnt exist after it https://i.gyazo.com/616baa5b2a387882d39d5588a23ce924.png RobloxianDestory 262 — 7y
0
What do you recommend I should do? 8391ice 91 — 7y
0
try seeing if it will work on a new server. RobloxianDestory 262 — 7y
0
Still nothing. 8391ice 91 — 7y
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." 8391ice 91 — 7y
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" RobloxianDestory 262 — 7y
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 == RobloxianDestory 262 — 7y
Ad

Answer this question