I might've asked this before but I don't know on how to make a data store for health. All I know is making data stores that are associated to leaderstats such as cash and level. I looked up online and even here but I can't seem to find anything about them that work. So here's the save data:
1 | function savedata(dataname, playerid, value) |
2 | if InStudio then return end |
3 | dataname:SetAsync(playerid, value) |
4 | end |
And I decided to add a starting health for the player:
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | player.CharacterAdded:Connect( function (char) |
3 | char.Humanoid.MaxHealth = 250 --Starting Health |
4 | player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth --Sets player health to max |
5 | end ) |
6 | end ) |
And Health change when player levels up
1 | player.Character.Humanoid.MaxHealth = levelz.Value * 50 + 250 --Change 100 to the health value |
2 | player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth --Sets player health to max |
01 | local HealthData = game:GetService( "DataStoreService" ):GetDataStore( "PlayerHealthData" ) |
02 | local DataKey = "~~" -- ..UserId |
03 |
04 |
05 | -- Load The Health |
06 | function loadHealth(Character) |
07 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
08 | local PlayerHealthData = HealthData:GetAsync(DataKey..player.UserId) -- Players Data In The Data Store |
09 | if PlayerHealthData then -- Checks If Player Has Data |
10 | Humanoid.MaxHealth = PlayerHealthData [ 1 ] -- Sets Max Health To Stored Health Value In The DataStore |
11 | Humanoid.Health = Humanoid.MaxHealth -- Sets same as MaxHealth |
12 | else -- If Player Does Not Have Data |
13 | Humanoid.MaxHealth = 100 - Set Default Health |
14 | Humanoid.Health = Humanoid.MaxHealth -- Sets same as MaxHealth |
15 | end |
i know someone else answered this but you still had some question about how to do it when the maxhealth changed so here it is.
ik the OldMax Table and stuff isnt very necessary but eh