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.
function Track(Humanoid) local Last = Humanoid.Health local function HealthChanged(Left) if Left < Last then local Part = Humanoid.Parent:FindFirstChildWhichIsA("BasePart") if Part then -- label stuff i put here -- wait(.1) if HealthChanged then return else wait(3) label.Visible = false end end Last = Left end end Humanoid.HealthChanged:connect(HealthChanged) 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):
function Track(Humanoid) local Last = Humanoid.Health local function HealthChanged(Left) if Left < Last then local Part = Humanoid.Parent:FindFirstChildWhichIsA("BasePart") if Part then -- label stuff i put here -- wait(.1) if HealthChanged then return else wait(3) label.Visible = false end end Last = Left end end Humanoid.HealthChanged:connect(HealthChanged) end
My edited script:
function Track(Humanoid) local Last = Humanoid.Health Humanoid.HealthChanged:Connect(function(health) if health < Last then Last = health local Part = Humanoid.Parent:FindFirstChildWhichIsA("BasePart") if Part then local label = script.Parent -- whatever the label was label.Visible = false end end end) end -- 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
if HealthChanged then 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
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
function Track(Humanoid) local Last = Humanoid.Health local function HealthChanged(Left) if Left < Last then local Part = Humanoid.Parent:FindFirstChildWhichIsA("BasePart") if Part then -- label stuff i put here -- local label = .parent -- Set here your label wait(.1) if HealthChanged then return else wait(3) label.Visible = false end end Last = Left end end Humanoid.HealthChanged:Connect(HealthChanged) -- Capital C in "Connect" end
I hope it works for you :D