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

How to properly use WaitForDataReady?

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

✓ Accepted answer

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)

4 comments

0

Attempted your fix, updated script as shown above. Never reaches the second print.

0

Are you testing on an actual ROBLOX game server, and also receiving no errors?

0

Oh, no. Let me test it out now.

0

I just tested, worked flawlessly. Thank you so much.

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

1 comment

0

I'm trying to have it so it frequently updates it. Preferably every second.

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