I don't know what is the problem, but when I leave in-studio from playtesting solo, Studio freezes then after some seconds, it works fine again but an error pops up. 14:04:41.768 - Not running script because past shutdown deadline (x10)
I poked around and I think it has something to do with datastores, which I have in my game. here is the code:
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local data 1 = datastore:GetDataStore( "mymoneydata" ) |
03 |
04 | game.Players.PlayerAdded:connect( function (player) |
05 | local leaderstats = Instance.new( "Folder" ,player) |
06 | leaderstats.Name = "leaderstats" |
07 | local greenmoney = Instance.new( "NumberValue" , leaderstats) |
08 | greenmoney.Name = "green_paper" |
09 | greenmoney.Value = data 1 :GetAsync(player.UserId) or 0 |
10 | data 1 :SetAsync(player.UserId, greenmoney.Value) |
11 |
12 | game.Players.PlayerRemoving:connect( function () |
13 | data 1 :SetAsync(player.UserId, greenmoney.Value) |
14 | end ) |
15 | end ) |
I don't know what this is or how to fix it, and its annoying. please help.
Hi, I am not sure of my answer, but I think the problem is that when a script saves something to the datastore, we have to wait like 10 seconds to let the datastore save THEN we can save again. So at line 10, when the player enters the game, the script saves his stats, but if the player leaves the game JUST AFTER he joined, the datastore will no have time to save his stats again at line 13. What I suggest to do is to delete line 10, so that whenever the player leaves, the datastore will be ready to save:
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local data 1 = datastore:GetDataStore( "mymoneydata" ) |
03 |
04 | game.Players.PlayerAdded:connect( function (player) |
05 | local leaderstats = Instance.new( "Folder" ,player) |
06 | leaderstats.Name = "leaderstats" |
07 | local greenmoney = Instance.new( "NumberValue" , leaderstats) |
08 | greenmoney.Name = "green_paper" |
09 | greenmoney.Value = data 1 :GetAsync(player.UserId) or 0 |
10 |
11 | game.Players.PlayerRemoving:connect( function () |
12 | data 1 :SetAsync(player.UserId, greenmoney.Value) |
13 | end ) |
14 | end ) |
Hope this helped!