Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to save your MaxHealth when you player dies? (RPG Game)

Asked by
jm34 7
8 years ago

In my RPG Game, whenever you level up your health is increased;


function onLevelUp(player, XP, level) wait(0.1) player.Character.Humanoid.Health = player.leaderstats.PwrLvl.Value * 100 + 100 player.Character.Humanoid.MaxHealth = player.leaderstats.PwrLvl.Value * 100 + 100


But when you die your maxhealth that you earned goes away. But when you respawn it saves al except MaxHealth your other stats that I implemented.

If you read this can you help me make a script that increases your maxhealth like shown when you respawn? Thanks. -jm34

2 answers

Log in to vote
1
Answered by 8 years ago

You could use game.StarterPlayer.StarterHumanoid.MaxHealth = 250

source: http://wiki.roblox.com/index.php?title=API:Class/StarterPlayer

0
So what I did was I made a script that went like this: game.StarterPlayer.StarterHumanoid.MaxHealth = game.Players.Player.leaderstats.PwrLvl.Value * 100 + 100 game.StarterPlayer.StarterHumanoid.Health = game.Players.Player.leaderstats.PwrLvl.Value * 100 + 100 and put it in the workspace. Then I made a StarterHumanoid and put that in the starterplayer, but it didnt work. jm34 7 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

A good way to do this would be to put a NumberValue in the player that will save the MaxHealth. Then, whenever the player's character is respawned, you can set the Humanoid's MaxHealth to the Value of that NumberValue. You can use the CharacterAdded method for this:

assuming that you have a variable called player that points to the player and that you've already created the NumberValue StoredMaxHealth

player.CharacterAdded:connect(function(char)
    char.Humanoid.MaxHealth = player.StoredMaxHealth.Value;
end);
0
Oh yes thank you very much! I wil try this method. jm34 7 — 8y
0
Sorry lightning, i'm not super advanced at making scripts, and my idea was to make it another leaderstat but I have too many leaderstats so I will need you to help me make this script further. jm34 7 — 8y

Answer this question