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

how do you get the number inside of MaxHealth?

I want to make a safe zone that makes the player's health infinite, I realized that it also heals the player to max health. Anyways, the problem is I want to get the actual number from max health, a number that I can add to and subtract from without changing the actual value. I want the value of the MaxHealth to be a int value.

Script:

		local HealthFolder = Instance.new("Folder",player)
		HealthFolder.Name = "HealthFolder"
		local OldMaxHealth = Instance.new("IntValue",HealthFolder)
		OldMaxHealth.Name = "OldMaxHealth"
		local OldHealth = Instance.new("IntValue",HealthFolder)	
		OldHealth.Name = "OldHealth"

		OldMaxHealth.Value = Humanoid.MaxHealth
		OldHealth.Value = Humanoid.MaxHealth

2 answers

this makes no sense, you want it to change but also not change? I think your trying to get the value and be able to use it instead of really changing it, well simple.

MAKE A VALUE!! VALUES DO NOT CHANGE UNLESS YOU CALL THEM!

example,

script.Name = "E"

and then i do this:

value1 = script.Name

so right now value1 = "E". but then if i change the script.Name = "A", then the value doesnt change unless you call it again and/or change it again, so the value1 = "E" still. So no worry about it doing that, jsut make a value!

maxHealthVal = Humanoid.Maxhealth

and there ya go, it wont change the actualy maxhealth of the humanoid but it will change the value instead which ORIGINATED from the maxhealth when you set it to the maxhealth.

hope this helps :3

You can just make a new variable and change its value to the value of the max health. This way you have a variable which you can change but doesn't affect the actual max health of the player.

local variable = humanoid.MaxHealth

Lets say the maxhealth of that humanoid is 100

humanoid.MaxHealth is referencing to value of the MaxHealth itself not the Object itself, that's why the value of the variable will be a number value "100" and not an object "humanoid.MaxHealth"

Reading this may help you understand.

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