I am trying to store the Humanoid properties so when a character resets or leaves the game, the maxhealth and health save, but doesnt work, here is the script-
local datastore = game:GetService("DataStoreService"):GetDataStore("NPS")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character.Humanoid
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
humanoid.MaxHealth = storeditems[1]
humanoid.Health = storeditems[2]
else
local items = {humanoid.MaxHealth, humanoid.Health}
datastore:SetAsync(key, items)
end
end)
player.CharacterRemoving:Connect(function(character)
local items = {character.Humanoid.MaxHealth, character.Humanoid.Health}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
end)
end)

1 comment
Try Players.PlayerRemoving instead of CharacterRemoving. If not, try to use game:BindToClose() along side it.