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 stop the Players health from regenerating?

I've tried this two ways. Please note that my script is in the StarterCharacterScripts folder.

Approach 1:

script.Parent.Health.Disabled = true

Approach 2:

script.Parent.Health:Destroy()

Either way I keep getting the same error:

20:09:24.534 - Health is not a valid member of Model

How can I successfully stop the Health script from working? Any and all help is appreciated.

2 answers

✓ Accepted answer

The problem is that Health is not loaded when the script is loaded; meaning the script is trying to index something that currently does not exist.

To fix this, simply use WaitForChild:

script.Parent:WaitForChild("Health"):Destroy() -- RIP health regen

Also, WaitForChild has a second parameter that has been recently added. Previously, it would wait infinitely for something if it did not exist, causing your code to essentially stop. But now you can add a maximum wait time:

object:WaitForChild("ObjectName",5) -- only searches for ObjectName for 5 seconds

Hope I helped!

~TDP

1 comment

0

Thanks, Cheers mate!

You do not need to actually create add code to a script. Simply name it Health, and add it to game.StarterPlayer.StarterPlayerScripts

Why

If you add a script to StarterCharacter, then it will remove all of the scripts in character with the same name. The way the character regenerates health is through a script named Health. Simply putting an empty script named Healthinto StarterPlayer will replace the regeneration with a blank script.

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