Well, I did this script quickly and it does not work for me for some reason, according to me it should save life and MaxHealth, but it does not
local DataStore = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local HealthData = DataStore:GetDataStore("HealthData")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Humanoid = char:WaitForChild("Humanoid")
local Get_Data = nil
local Success, err = pcall(function()
Get_Data = HealthData:GetAsync(plr.UserId)
end)
if Success and Get_Data ~= nil then
if Get_Data.Health >= Get_Data.MaxHealth then
Humanoid.MaxHealth = Get_Data.MaxHealth
Humanoid.Health = Get_Data.MaxHealth
else
Humanoid.MaxHealth = Get_Data.MaxHealth
Humanoid.Health = Get_Data.Health
end
else
Humanoid.MaxHealth = 100
Humanoid.Health = 100
end
end)
end)
Players.PlayerRemoving:Connect(function(plr)
plr.CharacterRemoving:Connect(function(char)
local Get_Data = {
Health = char.Humanoid.Health;
MaxHealth = char.Humanoid.MaxHealth;
}
local Success, err = pcall(function()
HealthData:SetAsync(plr.UserId, Get_Data)
end)
if Success then
print("Se ha guardado correctamente / Has been saved successfully")
else
print("hubo un error al guardar / there was an error saving")
warn(err)
end
end)
end)