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
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
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
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.
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.
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
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.
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