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

How can I make MaxHealth equal to Endurance?

Asked by 7 years ago

^ Title

I'd like to make my Max Health equal to the player's endurance

In the workspace there is a script, script contains as follows:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character.Humanoid.MaxHealth = "What Here?!"
    end)
end)

The what here part is what I'd like to change, I'm not sure how to refer to Endurance.Value

In the ServerScriptService there is the system script which currently contains (working code):

game.Players.PlayerAdded:connect(function(Player)
    local Data = Instance.new("IntValue",Player)
    Data.Name = "Data"
    local XP = Instance.new("IntValue",Data)
    XP.Name = "XP"
    XP.Value = 0
    local Level = Instance.new("IntValue",Data)
    Level.Name = "Level"
    Level.Value = 1
    local Strength = Instance.new("IntValue",Data)
    Strength.Name = "Strength"
    Strength.Value = 1
    local Endurance = Instance.new("IntValue",Data)
    Endurance.Name = "Endurance"
    Endurance.Value = 50
    local Agility = Instance.new ("IntValue",Data)
    Agility.Name = "Agility"
    Agility.Value = 1

    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connnect(function(character)
            character.Humanoid.MaxHealth = Endurance
        end)
    end)

    XP.Changed:connect(function() XPChange(Player,XP,Level,Endurance) end)

end)

function XPChange(Player,XP,Level,Endurance)
    if XP.Value >= Level.Value*10 + 100 then
        XP.Value = 0
        Level.Value = Level.Value + 1
        Endurance.Value = Endurance.Value + 50
    end
end
0
It would be better for you if you just created the IntValues in Explorer in a folder and then called :Clone() on that folder, it can save a lot of lines of code. NotInventedHere 158 — 7y

1 answer

Log in to vote
1
Answered by
sad_eyez 162
7 years ago
Edited 7 years ago
game.Players.PlayerAdded:Connect(function(player)
    local Data = Instance.new("IntValue",player)
    Data.Name = "Data"
    local XP = Instance.new("IntValue",Data)
    XP.Name = "XP"
    XP.Value = 0
    local Level = Instance.new("IntValue",Data)
    Level.Name = "Level"
    Level.Value = 1
    local Strength = Instance.new("IntValue",Data)
    Strength.Name = "Strength"
    Strength.Value = 1
    local Endurance = Instance.new("IntValue",Data)
    Endurance.Name = "Endurance"
    Endurance.Value = 50
    local Agility = Instance.new ("IntValue",Data)
    Agility.Name = "Agility"
    Agility.Value = 1

    player.CharacterAdded:Connect(function(character)
        local hum = character:FindFirstChild("Humanoid")
        hum.Health = Endurance.Value
        hum.MaxHealth = Endurance.Value
        print(hum.MaxHealth)
    end)
end)

for one, you don't need to use PlayerAdded twice here is the code I edited a bit, try it, and it should work

0
Tried that beforehand, Endurance isn't a recognised value RSYamamoto 2 — 7y
0
you have to make sure it knows where the value is sad_eyez 162 — 7y
0
Just re-edited my post, try that sad_eyez 162 — 7y
0
It works, but when your level increases the MaxHealth doesn't increase with it.. Makes it pointless RSYamamoto 2 — 7y
View all comments (2 more)
0
A player would have to respawn, and the Endurance value would have to be changed when they leveled up. So that would be your mistake. Vezious 310 — 7y
0
it's your job to make a script that changes the health and maxhealth when they level up sad_eyez 162 — 7y
Ad

Answer this question