local healthtostore = game:GetService("DataStoreService")

local hpStore = healthtostore:GetDataStore("Health")

local plr = game:GetService("Players")

plr.PlayerAdded:connect(function(p)
	local default_properties = {
		100;
	}
	
	local char = p.Character or p.CharacterAdded:wait()
	
	local humanoid = char:WaitForChild("Humanoid")
	local data
	local succ, err = pcall(function()
		data = hpStore:GetAsync(p.UserId)
	end)
	
	if succ then
		humanoid.MaxHealth = data
		print("Successful")
	else
		humanoid.MaxHealth = default_properties[1]
		warn(err)
		print("Something went wrong")
	end
	
end)


game.Players.PlayerRemoving:Connect(function(p)
	local char = p.Character or p.CharacterAdded:wait()

	local humanoid = char:WaitForChild("Humanoid")
	
	local succ, err = pcall(function()
		hpStore:SetAsync(p.UserId, humanoid.MaxHealth)
	end)
	
	if succ then
		print("Saved")
	else
		print("Error whilst saving the data")
	end
end)

2 comments

0

really the only 2 things i can think is 1) bindtoclose or an extremely rare case where you need to tonumber humanoid.MaxHealth on 38 but you prob dont

0

well thanks for atleast trying