Well the script I made makes it save the data with ProfileService of the humanoid when it is deleted or when the humanoid dies (when the humanoid dies, its maxHealth is put to its health), this all works, however it does not load the maximum data of health and health in the humanoid
local DataManager = require(game.ServerScriptService:WaitForChild("DataStore"):WaitForChild("Configurations"):WaitForChild("DataManager"))
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local Profile = DataManager:Get(player, true)
if not Profile then
repeat task.wait(0.1)
Profile = DataManager:Get(player, true)
until Profile or (not player.Parent)
end
if Profile then
task.wait(0.1)
player.CharacterAdded:Connect(function(char)
local Health_Services = Profile.Data.PlayerServices.CharacterServices.Health_Services
wait(0.3)
local Humanoid = char:WaitForChild("Humanoid")
Humanoid.DIed:Connect(function()
Profile.Data.PlayerServices.CharacterServices.Health_Services.Max_Health = char.Humanoid.MaxHealth
Profile.Data.PlayerServices.CharacterServices.Health_Services.Health = char.Humanoid.MaxHealth
end)
repeat wait()
Humanoid.MaxHealth = Health_Services.Max_Health
Humanoid.Health = Health_Services.Health
until Humanoid.Health == Health_Services.Health and Humanoid.MaxHealth == Health_Services.Max_Health
end)
player.CharacterRemoving:Connect(function(character)
local Health_Services = Profile.Data.PlayerServices.CharacterServices.Health_Services
if character.Humanoid.Health ~= Health_Services.Max_Health then
Profile.Data.PlayerServices.CharacterServices.Health_Services.Max_Health = character.Humanoid.MaxHealth
Profile.Data.PlayerServices.CharacterServices.Health_Services.Health = character.Humanoid.Health
end
end)
end
end)
this is the part where you should load health:
repeat wait()
Humanoid.MaxHealth = Health_Services.Max_Health
Humanoid.Health = Health_Services.Health
until Humanoid.Health == Health_Services.Health and Humanoid.MaxHealth == Health_Services.Max_Health