Hello! This is something I'm not sure what this is called or how to do fix this, but how this works is a gui that appears and dissapears when it is health changed. But seeing that as it continues to be damaged for more than 3 seconds, the gui starts flashing instead of resetting the 3 seconds before disabling the healthbar. How do I resolve this issue? Thanks.
local Humanoid = script.Parent.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") Humanoid.HealthChanged:Connect(function() script.Parent.Parent.Parent.HealthBar.Enabled = true script.Parent.HealthNum.Text = math.floor(Humanoid.Health) .. " / " .. math.floor(Humanoid.MaxHealth) local pie = (Humanoid.Health / Humanoid.MaxHealth) script.Parent.Healthbar.Size = UDim2.new(pie, 0, 1, 0) wait(3) -- This part where I want to reset the wait if the function's called or fired again. script.Parent.Parent.Parent.HealthBar.Enabled = false end)
You can simply use a bool and if statements as a debounce. I'll use your script as an example of it.
local Humanoid = script.Parent.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") local bool = false Humanoid.HealthChanged:Connect(function() if not bool then bool = true script.Parent.Parent.Parent.HealthBar.Enabled = true script.Parent.HealthNum.Text = math.floor(Humanoid.Health) .. " / " .. math.floor(Humanoid.MaxHealth) local pie = (Humanoid.Health / Humanoid.MaxHealth) script.Parent.Healthbar.Size = UDim2.new(pie, 0, 1, 0) script.Parent.Parent.Parent.HealthBar.Enabled = false else task.wait(0.5) bool = false end end)