Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make MaxHealth equal to Endurance?

^ 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

1 comment

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.

1 answer

✓ Accepted answer
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

6 comments

0

Tried that beforehand, Endurance isn't a recognised value

0

you have to make sure it knows where the value is

0

Just re-edited my post, try that

0

It works, but when your level increases the MaxHealth doesn't increase with it.. Makes it pointless

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.

0

it's your job to make a script that changes the health and maxhealth when they level up

This discussion is preserved as it was. New answers, comments, and votes are closed.