I am making a script that makes the wooden wall have health for one of my games. I am making it glow a certain colour representing its current health for a few seconds. After writing script.Parent.Transparency = [Value] wait(0.01)
10 times I ran into a problem. It continues to loop for obvious reasons, its part of a while loop. I need to stop it from looping more than once but I cannot break the script as it would not turn red once the health goes lower. How can I prevent this script from looping without breaking the whole loop? Here is my workspace, extras, frames, panels and scripts are folders.
game
workspace
woodenwall
Extras
humanoid
Hitbox
Frames(These are parts not GUI's)
Frame
SubFrame
Panels
[Ton of parts i will not list as it is not important anyways]
Scripts
DestroyService
Here is the code I am having trouble with.
local humanoid = script.Parent.Parent.Extras:FindFirstChild('Humanoid')
local hitbox = script.Parent.Parent.Extras.HitBox
local pannels = script.Parent.Parent.Pannels
local frames = script.Parent.Parent.Frames
while true do
wait(0.001)
if humanoid.Health == 500 then
else
if humanoid.Health <= 300 then
hitbox.BrickColor = BrickColor.new('New Yeller')
hitbox.Transparency = 0.99
wait(0.01)
hitbox.Transparency = 0.98
wait(0.01)
hitbox.Transparency = 0.97
wait(0.01)
hitbox.Transparency = 0.96
wait(0.01)
hitbox.Transparency = 0.95
wait(0.01)
hitbox.Transparency = 0.94
wait(0.01)
hitbox.Transparency = 0.93
wait(0.01)
hitbox.Transparency = 0.92
wait(0.01)
hitbox.Transparency = 0.91
wait(0.01)
hitbox.Transparency = 0.90
wait(0.01)
hitbox.Transparency = 0.91
wait(0.01)
hitbox.Transparency = 0.92
wait(0.01)
hitbox.Transparency = 0.93
wait(0.01)
hitbox.Transparency = 0.94
wait(0.01)
hitbox.Transparency = 0.95
wait(0.01)
hitbox.Transparency = 0.96
wait(0.01)
hitbox.Transparency = 0.97
wait(0.01)
hitbox.Transparency = 0.98
wait(0.01)
hitbox.Transparency = 0.99
wait(0.01)
hitbox.Transparency = 1
if humanoid.Health <= 100 then
hitbox.BrickColor = BrickColor.new('Really red')
if humanoid.Health <= 0 then
hitbox:Destroy()
for i, v in pairs(pannels:GetChildren())do
wait(0.1)
v:Destroy()
end
for i, v in pairs(frames:GetChildren())do
wait(0.1)
v:Destroy()
end
end
end
end
end
end
Can someone please help me solve this problem? Thank you for your time :)
- FruitPuunch
