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?
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)