Max Health increase in studio works perfectly but...?
Asked by
6 years ago Edited 6 years ago
Whenever I increase max health in studio when a stat is changed, the health regens to the max health. However, in the actual game, the health only regens up to 100 regardless of how much the max health is. Here is the script:
001 | player = game.Players.LocalPlayer |
002 | local Str = player.Stats.Strength.Value |
003 | local Agi = player.Stats.Agility.Value |
004 | local Int = player.Stats.Intelligence.Value |
005 | local Def = player.Stats.Defense.Value |
006 | local Vit = player.Stats.Vitality.Value |
007 | local Dex = player.Stats.Dexterity.Value |
011 | local CriticalDamage = 0 |
015 | for j,k in pairs (player.Equip:GetChildren()) do |
016 | if k.itemType.Value = = "Weapon" then |
017 | Damage = k.itemDamage.Value |
018 | Speed = k.itemSpeed.Value |
019 | Critical = k.itemCritical.Value |
020 | CriticalDamage = k.itemCritDamage.Value |
022 | script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring (Damage) |
023 | script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring (Critical) .. "%" |
024 | script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring (CriticalDamage) |
029 | function removeDamage() |
030 | if weapon = = nil then |
035 | script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring (Damage) |
039 | function onstatChange(x) |
042 | if x = = "Strength" then |
043 | player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+ 2 |
044 | player.Character.Humanoid.Health = player.Character.Humanoid.Health + 4 |
045 | script.Parent.Parent.Information.HP.Text = "HP: " .. tostring (player.Character.Humanoid.MaxHealth) |
046 | script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring (Damage) |
049 | if x = = "Agility" then |
050 | script.Parent.Parent.Information.ATKSpeed.Text = "ATKSpeed: " .. tostring (Speed) |
052 | if x = = "Intelligence" then |
053 | script.Parent.Parent.Information.MP.Text = "MP: " .. tostring ((player.Stats.Intelligence.Value* 4 )+ 100 ) |
055 | if x = = "Defense" then |
056 | script.Parent.Parent.Information.damageResistance.Text = "DMG Resist%: " .. tostring (player.Stats.Defense.Value/ 5 ) .. "%" |
058 | if x = = "Vitality" then |
059 | player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+ 4 |
060 | player.Character.Humanoid.Health = player.Character.Humanoid.Health + 4 |
062 | script.Parent.Parent.Information.HP.Text = "HP: " .. tostring (player.Character.Humanoid.MaxHealth) |
063 | script.Parent.Parent.Information.Stamina.Text = "Stamina: " .. tostring (player.PlayerGui.mainUI.statHolder.staminaHolder.staminaBar.MaxStamina.Value) |
065 | if x = = "Dexterity" then |
066 | script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring (Critical) .. "%" |
067 | script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring (CriticalDamage) |
073 | player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+( 2 *Str)+( 4 *Vit) |
074 | player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth |
075 | script.Parent.Parent.Information.HP.Text = "HP: " .. tostring (player.Character.Humanoid.MaxHealth) |
076 | script.Parent.Parent.Information.MP.Text = "MP: " .. tostring ((player.Stats.Intelligence.Value* 4 )+ 100 ) |
077 | script.Parent.Parent.Information.ATKSpeed.Text = "ATKSpeed: " .. tostring (Speed) |
078 | script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring (Damage) |
079 | script.Parent.Parent.Information.Stamina.Text = "Stamina: " .. tostring (player.PlayerGui.mainUI.statHolder.staminaHolder.staminaBar.MaxStamina.Value) |
080 | script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring (Critical) .. "%" |
081 | script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring (CriticalDamage) |
084 | player.CharacterAdded:Connect(addChar) |
085 | player.Equip.ChildAdded:Connect(damage) |
086 | player.Equip.ChildRemoved:Connect(removeDamage) |
087 | player.Stats.Strength.Changed:Connect( function () |
088 | onstatChange( "Strength" ) |
090 | player.Stats.Agility.Changed:Connect( function () |
091 | onstatChange( "Agility" ) |
093 | player.Stats.Intelligence.Changed:Connect( function () |
094 | onstatChange( "Intelligence" ) |
096 | player.Stats.Defense.Changed:Connect( function () |
097 | onstatChange( "Defense" ) |
099 | player.Stats.Vitality.Changed:Connect( function () |
100 | onstatChange( "Vitality" ) |
102 | player.Stats.Dexterity.Changed:Connect( function () |
103 | onstatChange( "Dexterity" ) |
So I tried this in my local script
2 | game.ReplicatedStorage.AddHealth:FireServer() |
3 | script.Parent.Parent.Information.HP.Text = "HP: " .. tostring (player.Character.Humanoid.MaxHealth) |
4 | script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring (Damage) |
and in my server script in workspace
1 | game.ReplicatedStorage.AddHealth.OnServerEvent:connect( function (player) |
2 | player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+ 2 |
it says AddHealth is not a valid member