Okay, so a backstory:
I've whipped up a tool that heals you, but one problem is that the healing doesn't stop at the Max Health, and just keeps on healing your health above the Max Health, which is a problem as you could turn yourself into a monster with 1000+ health, when you're only supposed to have 100. Instead of fixing this, I decided it would be neat to turn it into a feature and make it to if you "overheal" yourself you can poison yourself and die.
So now I created a LocalScript that would quickly drain your health once you're 50 hp above your Max Health (I'm EXTREMELY NEW to scripting, and this is my first try at creating a script):
local Humanoid = game.Players.LocalPlayer.Character.Humanoid function Kill() if Humanoid.Health > Humanoid.MaxHealth+50 then repeat Humanoid:TakeDamage(30) wait(1) until Humanoid.Died end end Kill()
I know that I wrote a script that's entirely wrong (I've tested it) and I'm hoping if I could find what's wrong with it, and find out how I can fix it.
It would also help if you can show me what's wrong with the script to help me for future scripts I may write.
EDIT:
Ok 6 month later, me reading this again I've seen the problem. Old me forgot to loop it.
EDIT 2:
Ok pogger me like 1.5 years later wants to say hi.
Good job on setting up a variable for the player's humanoid object. From here you can use the Humanoid's HealthChanged event to detect whenever the health of the player changes like so:
local humanoid = game.Players.LocalPlayer.Character.Humanoid local currentHealth = humanoid.Health
humanoid.HealthChanged:Connect(function() if currentHealth > 150 then repeat humanoid.TakeDamage(30) until humanoid:Died() end end) end) Please excuse the formatting errors, this was written on phone, but i hope this helps!