So I have this rpg game and I want it to have a level system and an armor system I tried using an armor that adds 100 MaxHealth to the player and it works perfectly I also have a healing pond that heals the player to the maxhealth instantly and it also works
But the problem is when I level up, the GUI that shows the maxhealth increased to for instance, 300, but when I print my humanoid maxhealth value it stays at 100
For the armor script and healing script I use the ontouch(part) function to get my character, while in the level up system I use a localscript thus I use a localplayer and get the character from there on
Can someone help to explain and give a solution on why the humanoid maxhealth stays at 100? while a normal script does the job properly?
LocalScript :
local PlayersService = game:GetService("Players")
local Player = PlayersService.LocalPlayer
repeat wait() until Player.Character ~= nil
repeat wait() until Player.Character:FindFirstChild("Humanoid")
repeat wait() until Player.leaderstats
repeat wait() until Player.Stats
Player.leaderstats:WaitForChild("Lvl")
Player.leaderstats:WaitForChild("Gold")
local HUD = Game.Players.LocalPlayer.PlayerGui.HUD
HUD.Base:WaitForChild("HealthBar")
HUD.Base.HealthBar:WaitForChild("Fill")
HUD.Base.HealthBar:WaitForChild("CurrentHP")
HUD.Base:WaitForChild("ManaBar")
HUD.Base.ManaBar:WaitForChild("Fill")
HUD.Base.ManaBar:WaitForChild("CurrentMP")
HUD.Base:WaitForChild("GoldBox")
HUD.Base:WaitForChild("WalkSpeed")
HUD.Base:WaitForChild("CharacterPortrait")
HUD.Base.CharacterPortrait:WaitForChild("Level")
HUD.Base:WaitForChild("CharName")
--Display character name.
HUD.Base.CharName.Text = Game.Players.LocalPlayer.Name
function ShowGameOver()
HUD.Critical.Visible = false
HUD.Dead.Visible = true
end
Player.Character:WaitForChild("Humanoid").Died:connect(ShowGameOver)
if Player.Character:FindFirstChild("Humanoid") ~= nil then
if Game.Workspace.GAME_PROPERTIES.DefenseMode.Value == 3 then
if Player.Stats:FindFirstChild("Defense") ~= nil then
Player.Character.Humanoid.MaxHealth = (Game.Workspace.GAME_PROPERTIES.StartingHP.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerLevel.Value * Player.leaderstats.Lvl.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerConstitution.Value * Player.attributes.Constitution.Value) + Player.Stats.Defense.Value
end
else
Player.Character.Humanoid.MaxHealth = (Game.Workspace.GAME_PROPERTIES.StartingHP.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerLevel.Value * Player.leaderstats.Lvl.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerConstitution.Value * Player.attributes.Constitution.Value)
end
end
--When I level up
Player.leaderstats.Lvl.Changed:Connect(function()
print(Player)
local plrV = Player.Character:FindFirstChild("Humanoid")
if plrV ~= nil then
if Game.Workspace.GAME_PROPERTIES.DefenseMode.Value == 3 then
if Player.Stats:FindFirstChild("Defense") ~= nil then
plrV.MaxHealth = (Game.Workspace.GAME_PROPERTIES.StartingHP.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerLevel.Value * Player.leaderstats.Lvl.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerConstitution.Value * Player.attributes.Constitution.Value) + Player.Stats.Defense.Value
end
else
plrV.MaxHealth = (Game.Workspace.GAME_PROPERTIES.StartingHP.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerLevel.Value * Player.leaderstats.Lvl.Value) + (Game.Workspace.GAME_PROPERTIES.HPPerConstitution.Value * Player.attributes.Constitution.Value)
end
end
end)
Armor script :
local debounce = false
speed = script.Parent.Parent.MorphSettings.Walkspeed.Value
health = script.Parent.Parent.MorphSettings.Maxhealth.Value
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false and part.Parent:findFirstChild("ArmorTag")==nil and game.Players:GetPlayerFromCharacter(part.Parent)~=nil then
print(part.Parent)
debounce = true
human.MaxHealth = human.MaxHealth + health
human.Health = human.MaxHealth
human.WalkSpeed = speed
x=Instance.new("Script")
x.Name="ArmorTag"
x.Parent=part.Parent
wait(1)
debounce = false
end
end
script.Parent.Touched:connect(onTouch)
Healing pond script :
local debounce = false
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false and game.Players:GetPlayerFromCharacter(part.Parent)~=nil then
debounce = true
print(human.MaxHealth)
print(human.Health)
human.MaxHealth = human.MaxHealth
human.Health = human.MaxHealth
print(human.MaxHealth)
print(human.Health)
wait(1)
debounce = false
end
end
script.Parent.Pad.Touched:connect(onTouch)
I use alot of scripts from free models because im fairly new

1 comment
ow