Im trying to save the size of the players BodyWidthScale, BodyHeightScale, and BodyDepthScale. I want the values to load when a player resets, dies, or rejoines the game. Here's the script I have that doesn't work:
script.Parent= nil
local minute= (10)
function save(player)
local StatToSave = player.Chracter.Humanoid
---------
local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
local statstorage = StatToSave:GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
end
print(player.Name..' size autosaved')
end
game.Players.LocalPlayer.CharacterAdded:connect(function()
local player = game.Players.LocalPlayer
local StatToSave = player.Chracter.Humanoid:GetChildren()
local led= script:findFirstChild(StatToSave)
repeat wait() until led~= nil
local BWS = player.Character:findFirstChild("Humanoid").BodyWidthScale
BWS:Delete()
local BDS = player.Character:findFirstChild("Humanoid").BodyDepthScale
BDS:Delete()
local BHS = player.Character:findFirstChild("Humanoid").BodyHeightScale
BHS:Delete()
led:Clone().Parent= player.Character.Humanoid
local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
player.Character:FindFirstChild("Humanoid"):GetChildren() wait()
local stats = player.Character:FindFirstChild("Humanoid"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
end
if player.Name:match("Guest") then
print(player.Name..' has joined')
else end
while game.Players:findFirstChild(player.Name) do
save(player)
wait(minute)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
local statstorage = player.Character:findFirstChild("Humanoid"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
end
print(player.Name..' Size saved succesfully! ')
end)

1 comment
Please provide more detail: Is there an error message? Is your autosave working/message printing? What data are you trying to store: Is it a number, string? And what type of data is statstorage?