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

DataReady Not Working?

Asked by 9 years ago

I am an beginner-intermediate scripter, and I am new to the DataReady, until today. I looked on the ROBLOX wiki for a template on what I need to do to make a IntValue inside a folder that keeps track of how many times you have played.

01vcKey = "PlayerVisitCount"
02 
03game.Players.PlayerAdded:connect(function(player)
04    if player:WaitForDataReady() then
05 
06        local ls = Instance.new("Folder")
07        ls.Name = "Visits"
08        ls.Parent = player
09 
10        local vc = Instance.new("IntValue")
11        vc.Name = "VisitsCount"
12        vc.Parent = ls
13        vc.Value = player:LoadNumber(vcKey) + 1
14    end
15end)
View all 21 lines...

When I run it, the folder doesn't even appear inside the player. When I check the output window to see an error, there are no errors either.

2 answers

Log in to vote
0
Answered by
Juddily 33
9 years ago

Be aware that in test mode on studio, the player loads before the scripts. This means that your player is added to the game before your script has a chance to recognize it. I would do something like this:

01vcKey = "PlayerVisitCount"
02 
03local function AddPlayer(player)
04    if player:WaitForDataReady() then
05            local ls = Instance.new("Folder")
06            ls.Name = "Visits"
07            ls.Parent = player
08 
09            local vc = Instance.new("IntValue")
10            vc.Name = "VisitsCount"
11            vc.Parent = ls
12            vc.Value = player:LoadNumber(vcKey) + 1
13    end
14end
15 
View all 26 lines...

Also, don't quote me on this, but i'm not certain that data stores will work in test mode. If that code still isn't working, try printing to the dev console online.

Ad
Log in to vote
0
Answered by 9 years ago

:WaitForDataReady() is a yield method of player. Get rid of the if statement, and put the :WaitForDataReady() on its own, then it should work.

However, I advise strongly against DataPersistence, you should switch to the latest and more reliable DataStore's.

Answer this question