How to create an autosave to save player size?
Currently what this script is supposed to do is save the characters BodyWidthScale, BodyDepthScale, etc. when they leave, but that isn't working. But my actual goal for this script is to autosave these values periodically and also load when the player joins the game or resets. Any help would be appreciated!
01 | local DataStore = game.GetService( "DataStoreService" ):GetDataStore( "SizeSave" ) |
02 | game.Players.PlayerAdded:connect( function (player) |
03 | local key = "key-" ..player.userId |
04 | local Humanoid = player.Character:WaitForChild( "Humanoid" ) |
05 | local Stat = Humanoid:GetChildren() |
06 | local BHS = Humanoid.BodyHeightScale |
07 | local BWS = Humanoid.BodyWidthScale |
08 | local BDS = Humanoid.BodyDepthScale |
09 | local HS = Humanoid.HeadScale |
12 | local save = DataStore:GetAsync(key) |
20 | local load = { BHS.Value } |
21 | DataStore:SetAsync(key, load ) |
22 | local load 1 = { BWS.Value } |
23 | DataStore:SetAsync(key,load 1 ) |
24 | local load 2 = { BDS.Value } |
25 | DataStore:SetAsync(key,load 2 ) |
26 | local load 3 = { HS.Value } |
27 | DataStore:SetAsync(key,load 3 ) |
28 | print ( "Data Values Saved!" ) |
32 | game.Players.PlayerRemoving:connect( function (player) |
33 | local key = "key-" ..player.userId |
34 | local load = { player.Character.Humanoid:FindFirstChild( "BodyHeightScale" ).Value } |
35 | DataStore.SetAsync(key. load ) |
36 | local load 1 = { player.Character.Humanoid:FindFirstChild( "BodyWidthScale" ).Value } |
37 | DataStore.SetAsync(key.load 1 ) |
38 | local load 2 = { player.Character.Humanoid:FindFirstChild( "BodyDepthScale" ).Value } |
39 | DataStore.SetAsync(key.load 2 ) |
40 | local load 3 = { player.Character.Humanoid:FindFirstChild( "HeadScale" ).Value } |
41 | DataStore.SetAsync(key.load 3 ) |
42 | print ( "Data Values Loaded!" ) |