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!
local DataStore=game.GetService("DataStoreService"):GetDataStore("SizeSave")
game.Players.PlayerAdded:connect(function(player)
local key = "key-"..player.userId
local Humanoid = player.Character:WaitForChild("Humanoid")
local Stat = Humanoid:GetChildren()
local BHS = Humanoid.BodyHeightScale
local BWS = Humanoid.BodyWidthScale
local BDS = Humanoid.BodyDepthScale
local HS = Humanoid.HeadScale
wait(0.5)
local save = DataStore:GetAsync(key)
if save then
BHS.Value = save[1]
BWS.Value = save[2]
BDS.Value = save[3]
HS.Value = save[4]
else
local load = {BHS.Value}
DataStore:SetAsync(key,load)
local load1 = {BWS.Value}
DataStore:SetAsync(key,load1)
local load2 = {BDS.Value}
DataStore:SetAsync(key,load2)
local load3 = {HS.Value}
DataStore:SetAsync(key,load3)
print("Data Values Saved!")
end
end)
game.Players.PlayerRemoving:connect(function(player)
local key = "key-"..player.userId
local load = {player.Character.Humanoid:FindFirstChild("BodyHeightScale").Value}
DataStore.SetAsync(key.load)
local load1 = {player.Character.Humanoid:FindFirstChild("BodyWidthScale").Value}
DataStore.SetAsync(key.load1)
local load2 = {player.Character.Humanoid:FindFirstChild("BodyDepthScale").Value}
DataStore.SetAsync(key.load2)
local load3 = {player.Character.Humanoid:FindFirstChild("HeadScale").Value}
DataStore.SetAsync(key.load3)
print("Data Values Loaded!")
end)
