Script Repeats again and again

  1. What do you want to achieve? I wanna make it so whenever your low hp I want it to fade in but it repeats it again and again

  2. What is the issue? it repeats the fade-in sequence again and again for some reason and I’m not sure how to fix it since I’m not a scripter and only know how to script some things

  1. What solutions have you tried so far? I tried adding some stuff to the script but didn’t work
while true do
	if script.Parent.Humanoid.Health <= 20 then --change the 20 to the health you want to screen to change at
		game.Lighting.BlurLowHP.Enabled = true
		game.Lighting.LowHPEffectColor.Enabled = true
		wait(0)
		game.Lighting.BlurLowHP.Size = 4	
		game.Lighting.LowHPEffectColor.Saturation = 1
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 5	
		game.Lighting.LowHPEffectColor.Saturation = 0.8
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 6
		game.Lighting.LowHPEffectColor.Saturation = 0.6
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 7
		game.Lighting.LowHPEffectColor.Saturation = 0.4
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 8
		game.Lighting.LowHPEffectColor.Saturation = 0.2
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 9
		game.Lighting.LowHPEffectColor.Saturation = 0
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 10
		game.Lighting.LowHPEffectColor.Saturation = 0.25
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 11
		game.Lighting.LowHPEffectColor.Saturation = 0.5
		wait()
	else
		game.Lighting.BlurLowHP.Enabled = false
		game.Lighting.LowHPEffectColor.Enabled = false
	end
	wait()
end

Please help out!

2 Likes

Well you have it set on an infinite while loop so…

1 Like

This is a very terrible use of while true… Look into using the HealthChanged event Humanoid | Roblox Creator Documentation. You will also need some sort of debounce. Once their new health is <= 20, check if the debounce is enabled, if it isn’t run all the code and enable the debounce, when their health is > 20 disable the debounce.

2 Likes

If you don’t want it to repeat, simply delete the while true loop :smiley:

If you want to repeat you can also use RunTime FYI. While true do is REALLY laggy.

While loop will repeat your commands. So you can add variables for BlurLowHp.Size and Saturation and change them while loop goes. When humanoid has more than 20 hp (else) turn off effects and type “break” to stop the loop.

How will I be able to add that to my script? (Sorry I am not good at understanding scripting stuff)

local size = 4
local sat = 1
local satFlag = false
while true do
	if script.Parent.Humanoid.Health <= 20 then
		if game.Lighting.BlurLowHP.Enabled - false then
			game.Lighting.BlurLowHP.Enabled = true
			game.Lighting.LowHPEffectColor.Enabled = true
		else
			game.Lighting.BlurLowHP.Size = size	
			game.Lighting.LowHPEffectColor.Saturation = sat
			wait(0.08)
			if size < 12 then
				size += 1
			end
			if sat > 0 and not satFlag then
				sat -= 0.2
			else
				sat += 0.25
				satFlag = true
			end
		end
	else
		game.Lighting.BlurLowHP.Enabled = false
		game.Lighting.LowHPEffectColor.Enabled = false
		break
	end
	wait(0.01)
end

Need description?

This code was written fast, so I could make mistakes. Of course, I forgot wait

You can try with this, copy and paste:

local humanoid = script.Parent.Humanoid
local health = humanoid.Health

humanoid.HealthChanged:Connect(function()
	if health <= 20 then
		game.Lighting.BlurLowHP.Enabled = true
		game.Lighting.LowHPEffectColor.Enabled = true
		game.Lighting.BlurLowHP.Size = 4
		game.Lighting.LowHPEffectColor.Saturation = 1
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 5	
		game.Lighting.LowHPEffectColor.Saturation = 0.8
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 6
		game.Lighting.LowHPEffectColor.Saturation = 0.6
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 7
		game.Lighting.LowHPEffectColor.Saturation = 0.4
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 8
		game.Lighting.LowHPEffectColor.Saturation = 0.2
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 9
		game.Lighting.LowHPEffectColor.Saturation = 0
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 10
		game.Lighting.LowHPEffectColor.Saturation = 0.25
		wait(0.08)
		game.Lighting.BlurLowHP.Size = 11
		game.Lighting.LowHPEffectColor.Saturation = 0.5
	else
		game.Lighting.BlurLowHP.Enabled = false
		game.Lighting.LowHPEffectColor.Enabled = false
	end
end)

If you have problems, let me know (I’ll be busy)

@VEGAVEGA99 did right stuff too. It is righter to add function on health changing.

I tried all your scripts, Still doesn’t work :frowning:

I don’t want to delve into formulas, but third loop value is quite useless and second one should be 12. In the second loop iterator should be j or something else for avoiding conflicts.

did you try mine at all yet???

Yes I did, I tried all of the scripts but still doesnt work sadly. Not sure why it isnt working.

What script is it and where it is?

local Humanoid = script.Parent.Humanoid
local RepeatAmount = 3 -- this is how many times it will repeat

Humanoid.HealthChanged:Connect(function()
    local BlurLowHP = game.Lighting.BlurLowHP
    local LowHPEffectColor = game.Lighting.LowHPEffectColor
    if Humanoid.Health <= 20 then
        BlurLowHP.Enabled = true
        LowHPEffectColor.Enabled = true
        for i = 1, RepeatAmount, 1 do
            for ii = 4, 11, 1 do
                BlurLowHP.Size = ii
                if ii >= 10 then
                    LowHPEffectColor.Saturation = (0.25 * (ii - 9))
                else
                    LowHPEffectColor.Saturation = 1 - (0.2 * (ii - 4))
                end
                wait(0.08)
            end
        end
    else
        BlurLowHP.Enabled = false
        LowHPEffectColor.Enabled = false
    end
end)

my bad, I completely forgot to change it when writing

try my new one, should work better

Also can you, please, describe where do you put this script, if it isn’t work.

Screen Shot 2021-06-26 at 6.28.45 PM Screen Shot 2021-06-26 at 6.29.02 PM