I want this script to create a bloody screen as a player's health is dropping. The image will become denser and denser as the player's health becomes lower and lower. Can anyone solve this? I'm new to scripting and some of you may ignore this because it is so simple, it's just that I can't figure it out myself.
if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <100 then script.Parent.ImageTransparency = 0.1 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <90 then script.Parent.ImageTransparency = 0.2 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <80 then script.Parent.ImageTransparency = 0.3 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <70 then script.Parent.ImageTransparency = 0.4 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <60 then script.Parent.ImageTransparency = 0.5 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <50 then script.Parent.ImageTransparency = 0.6 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <40 then script.Parent.ImageTransparency = 0.7 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <30 then script.Parent.ImageTransparency = 0.8 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <20 then script.Parent.ImageTransparency = 0.9 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <10 then script.Parent.ImageTransparency = 1 end end end end end end end end end end
Here's a script much simplier than anything you did..
--//Code --This must be in a localScript! script.Parent.ImageTransparency = script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health/100 --//
Well First you gotta make sure its a localscript inside whatever you're trying to make become transparent
your code was very long and not efficient using elseif instead of if clears up all those ends
setting a variable using local variablename = game.location.objectname so you don't have all those parents
you neede to locate the players character therefore it was breaking because it didn't know where the character was so player.Character is what you have to do after setting the players variable
-- alright first lets locate the plater local player = game.Players.LocalPlayer -- now lets locate the frame local guiThing = script.Parent -- makes the code shorter so you don't type as much if player.Character.Humanoid.Health <=100 then guiThing.ImageTransparency = 1 elseif player.Character.Humanoid.Health <=90 then -- using elseif cleans up the code so you don't have 10 ends guiThing.ImageTransparency = .9 elseif player.Character.Humanoid.Health <=80 then guiThing.ImageTransparency = .8 elseif player.Character.Humanoid.Health <=70 then guiThing.ImageTransparency = .7 elseif player.Character.Humanoid.Health <=60 then guiThing.ImageTransparency = .6 elseif player.Character.Humanoid.Health <=50 then guiThing.ImageTransparency = .5 elseif player.Character.Humanoid.Health <=40 then guiThing.ImageTransparency = .4 elseif player.Character.Humanoid.Health <=30 then guiThing.ImageTransparency = .3 elseif player.Character.Humanoid.Health <=20 then guiThing.ImageTransparency = .2 elseif player.Character.Humanoid.Health <=10 then guiThing.ImageTransparency = .1 end
Hope this works and help and have a wonderful day! :)
You are missing the =.
When you are using an if
,while
or repeat
statement to check if a value is equal, higher or lower than another, you must add an extra = along with the other =, <, or >.
That way the script differentiates:
if variable == value then variable = value end --Variable equal to value if variable <= value then variable = value end --Variable less than value if variable >= value then variable = value end --Varable more than value
Like you did at your script, when you want to change the value of a property, you use just one =. Here's your corrected script, replacing < with <=:
if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 100 then script.Parent.ImageTransparency = 0.1 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 90 then script.Parent.ImageTransparency = 0.2 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 80 then script.Parent.ImageTransparency = 0.3 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 70 then script.Parent.ImageTransparency = 0.4 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 60 then script.Parent.ImageTransparency = 0.5 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 50 then script.Parent.ImageTransparency = 0.6 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 40 then script.Parent.ImageTransparency = 0.7 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 30 then script.Parent.ImageTransparency = 0.8 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 20 then script.Parent.ImageTransparency = 0.9 if script.Parent.Parent.Parent.Parent.Parent.Humanoid.Health <= 10 then script.Parent.ImageTransparency = 1 end end end end end end end end end end
This should work.