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

How to properly use WaitForDataReady?

Asked by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Hi,

I'm trying to save the value of an IntValue that's a descendant of a Player, but it doesn't seems to work.

game.Players.PlayerAdded:connect(function(p)
    print('1')
    p:WaitForDataReady()
    print('2')
    p.PrisonTime.Changed:connect(function()
        print('3')
while wait(1) do
    print('4')
    p:SaveNumber("PrisonTime", p.PrisonTime.Value)
    print("saved")
end
    end)
end)

It doesn't print 'saved'. Any tips?

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

WaitForDataReady() actually pauses execution until data is ready. While it returns a boolean, I'm not really sure if that signifies anything in particular.

Try instead

player:WaitForDataReady()

while wait(1) do
    p:SaveNumber("PrisonTime", p.PrisonTime.Value)
    print("saved")
end

Also note that data is never ready unless you are testing on a server (I think it has to be an actual game server, and not a test server, though I'm not sure).


Alternatively, use the boolean DataReady instead of this method, and continue with your if (though I think the approach with :WaitForDataReady() is much cleaner)

0
Attempted your fix, updated script as shown above. Never reaches the second print. Shawnyg 4330 — 10y
0
Are you testing on an actual ROBLOX game server, and also receiving no errors? BlueTaslem 18071 — 10y
0
Oh, no. Let me test it out now. Shawnyg 4330 — 10y
0
I just tested, worked flawlessly. Thank you so much. Shawnyg 4330 — 10y
Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Try just removing the while wait() do block, and just leave the if statement. The WaitForDataReady yields the script anyway.

0
I'm trying to have it so it frequently updates it. Preferably every second. Shawnyg 4330 — 10y

Answer this question