Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Doesn't remove the label when health changes?

Asked by
TechModel 118
3 years ago

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.

01function 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
View all 21 lines...
0
Also when other player do damage, i see their damage, strange when its a local script and i want the player to see it only them and their humanoid damage, not others. TechModel 118 — 3y

3 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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):

01function 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
View all 21 lines...

My edited script:

01function 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)
13end
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.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

'HealthChanged' is function in your code, not true or false so its weird to do

1if 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

1if Left < Last then
0
But then the problem is the text still shows more than 3 seconds? Thats why it was dumb of me to try out using the "HealthChanged" function TechModel 118 — 3y
0
I dont see any waiting value higher than 180 on code you showed, when the function Track() fires is still in myth TerranRecon 49 — 3y
0
Lmao he unknowingly used recursion in his script LOl greatneil80 2647 — 3y
Log in to vote
0
Answered by 3 years ago

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

01function 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
View all 22 lines...

I hope it works for you :D

Answer this question