I'm trying to make it so on line 9 the "HealthChanged" makes it return and keeps the duration of the text for 3 everytime i hit the humanoid, but it doesn't instead of that, it says visible forever.
01 | function Track(Humanoid) |
02 | local Last = Humanoid.Health |
03 | local function HealthChanged(Left) |
04 | if Left < Last then |
05 | local Part = Humanoid.Parent:FindFirstChildWhichIsA( "BasePart" ) |
06 | if Part then |
07 | -- label stuff i put here -- |
08 | wait(. 1 ) |
09 | if HealthChanged then |
10 | return |
11 |
12 | else |
13 | wait( 3 ) |
14 | label.Visible = false |
15 | end |
Unknowingly, you used recursion which silenced the error. This is a very awkward script just reading it, I will attempt to help you however.
Your script (For reference):
01 | function Track(Humanoid) |
02 | local Last = Humanoid.Health |
03 | local function HealthChanged(Left) |
04 | if Left < Last then |
05 | local Part = Humanoid.Parent:FindFirstChildWhichIsA( "BasePart" ) |
06 | if Part then |
07 | -- label stuff i put here -- |
08 | wait(. 1 ) |
09 | if HealthChanged then |
10 | return |
11 |
12 | else |
13 | wait( 3 ) |
14 | label.Visible = false |
15 | end |
My edited script:
01 | function Track(Humanoid) |
02 | local Last = Humanoid.Health |
03 | Humanoid.HealthChanged:Connect( function (health) |
04 | if health < Last then |
05 | Last = health |
06 | local Part = Humanoid.Parent:FindFirstChildWhichIsA( "BasePart" ) |
07 | if Part then |
08 | local label = script.Parent -- whatever the label was |
09 | label.Visible = false |
10 | end |
11 | end |
12 | end ) |
13 | end |
14 | -- make sure to Disconnect() HealthChanged to prevent memory leaks |
Note: One concern is that I'm not sure why you added "if HealthChanged", I'm just assuming you tried to detect when the health changed and forgot it was already being monitored.
Also, back early to what I said about recursion, if that actually ran which it didn't because no parameter was inputted, it would have reached the maximum frames in no time and you would have crashed.
Also make sure you call Track(humanoid) somewhere in the script so it actually begins monitoring the health changes.
'HealthChanged' is function in your code, not true or false so its weird to do
1 | if HealthChanged then |
2 | return |
and I think you better set value of "Last" more frequently
I dont know when function Track works but If it doesnt set frequently enough the phenomenon - when you get your health pretty low then regen health- Value of Last is low and your current health is high, so it can't be done after
1 | if Left < Last then |
Hello Chap
I have seen you need some Help, I will give you a fixed script [Maybe]
And also errors you did
First of all: I didn't see a label variable
And second: connect keyword must be like this : "Connect"
Here is your fixed script
01 | function Track(Humanoid) |
02 | local Last = Humanoid.Health |
03 | local function HealthChanged(Left) |
04 | if Left < Last then |
05 | local Part = Humanoid.Parent:FindFirstChildWhichIsA( "BasePart" ) |
06 | if Part then |
07 | -- label stuff i put here -- |
08 | local label = .parent -- Set here your label |
09 | wait(. 1 ) |
10 | if HealthChanged then |
11 | return |
12 |
13 | else |
14 | wait( 3 ) |
15 | label.Visible = false |
I hope it works for you :D