Nothing is being printed out when a player leaves?
Also, if I don't have the spawn(function() it will just take forever for the game to close (on studio) and save the players data. And once it has finally closed it would say "Not running script because past shutdown deadline (x247)"
01 | local DSS = game:GetService( "DataStoreService" ):GetDataStore( "Testing" ) |
09 | local function load (player) |
10 | local key = "user_" ..player.UserId |
12 | local success, data = pcall ( function () |
13 | return DSS:GetAsync(key) |
17 | print ( "Loaded " ..player.Name.. "'s Data!" ) |
23 | local leaderstats = Instance.new( "Folder" ,player) |
24 | leaderstats.Name = "leaderstats" |
26 | local Coins = Instance.new( "IntValue" ,leaderstats) |
29 | local Blocks = Instance.new( "IntValue" ,leaderstats) |
30 | Blocks.Name = "Blocks" |
32 | local Rebirths = Instance.new( "IntValue" ,leaderstats) |
33 | Rebirths.Name = "Rebirths" |
35 | Coins.Value = data.Coins |
36 | Blocks.Value = data.Blocks |
37 | Rebirths.Value = data.Rebirths |
39 | local CurrentRocket = Instance.new( "StringValue" ,player) |
40 | CurrentRocket.Name = "Current_Rocket" |
41 | CurrentRocket.Value = "Rocket" |
43 | print ( "Couldn't Load " ..player.Name.. "'s Data!" ) |
47 | local function save(player) |
48 | local key = "user_" ..player.UserId |
51 | Coins = player.leaderstats.Coins.Value, |
52 | Blocks = player.leaderstats.Blocks.Value, |
53 | Rebirths = player.leaderstats.Rebirths.Value, |
56 | local Success, message = pcall ( function () |
57 | DSS:SetAsync(key,Items) |
61 | print ( "Saved " ..player.Name.. "'s Stats" ) |
63 | print ( "Failed to save " ..player.Name.. "'s Stats" ) |
68 | game:BindToClose( function () |
69 | for _, player in ipairs (game.Players:GetPlayers()) do |
76 | game.Players.PlayerAdded:Connect( function (player) |
80 | game.Players.PlayerRemoving:Connect( function (player) |