Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ImageLabel script help?

Asked by
TrollD3 105
9 years ago

I want to make a call of duty death screen so its like when you are injured/ losing health, the screen starts to turn red. The screen either slowly goes away if you are not being injured or the screen will be bloody red when you are dead. I tried to make a script that would work like that but its not working and Idk if im right or not. This script is under an image label btw.


Player = script.Parent.Parent.Parent.Parent.Character s = Player.Humanoid while true do if s.Health <= 90 then script.Parent.ImageTransparency = .1 script.Parent.Visible = true while true do if s.Health <= 80 then script.Parent.ImageTransparency = .2 script.Parent.Visible = true while true do if s.Health <= 70 then script.Parent.ImageTransparency = .3 script.Parent.Visible = true while true do if s.Health <= 60 then script.Parent.ImageTransparency = .4 script.Parent.Visible = true if s.Health >= 50 then script.Parent.ImageTransparency = .5 script.Parent.Visible = true while true do if s.Health <= 40 then script.Parent.ImageTransparency = .6 script.Parent.Visible = true while true do if s.Health <= 30 then script.Parent.ImageTransparency = .7 script.Parent.Visible = true while true do if s.Health <= 20 then script.Parent.ImageTransparency = .8 script.Parent.Visible = true while true do if s.Health <= 10 then script.Parent.ImageTransparency = .9 script.Parent.Visible = true while true do if s.Health <= 0 then script.Parent.ImageTransparency = 0 script.Parent.Visible = true end end

2 answers

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Ok...so you made a couple mistakes. I'll try to explain them after this, but try this new script:

Player = script.Parent.Parent.Parent.Parent.Character
s = Player.Humanoid
while true do
    wait() --Needed so that it doesn't crash the game.
        script.Parent.ImageTransparency = (s.Health/100) --Credit to BlueTaslem for suggesting this
    end
end

So basically, I removed all the "while true do" statements. These wouldn't have worked anyways because you need to put a waitin their, so that it doesn't run infinitely and crash the game.

Also, I removed all of the if statements, and replaced them with a single line, that changes the transparency based on the players health.

Anyways, try using this script, and it should work now. If you have any further questions, please leave a comment below, and i'll see what I can do. Hope I helped :P

2
why even use `if`s when the formula for Transparency in terms of Health is so simple? BlueTaslem 18071 — 9y
0
Updated. Thanks for pointing that out, lol. dyler3 1510 — 9y
0
Thank you so much!! The both of you! You guys are life savers! TrollD3 105 — 9y
0
Haha, no prob. Glad I could help. dyler3 1510 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

You have the right idea for the logic but you should using loop like that as they are all infinite. Instead you should use this event.

HealthChanged note this is a localscript

Use this event to change the image transparency and remove all of the while loops.

Edit:-

Ok I have made a small piece of code which will help you.

  1. First you will need to add a screengui into the startergui, inside this place a frame.
  2. Change the frames size to this "{1, 0},{1, 0}" this will fill up the whole screen.
  3. Change the background colour to red or any other colour you want. 4.Change the background transparency to 1.

  4. add this localscript into the starterpack


local humanoid = game.Players.LocalPlayer.Character.Humanoid --Finds the humanoid of the local character. This is the player who is running the script. local gui = game.Players.LocalPlayer.PlayerGui --the players gui local gui1 = gui:WaitForChild("ScreenGui") --waits till the gui is available humanoid.HealthChanged:connect(function(health) --sets the transparency of the background to the players health divided by 100 as that is the players max health gui1.Frame.BackgroundTransparency = health /100 end) Hope this helps
0
Can u elaborate more on that? Im still a novice scripter... and im stll confused on what you mean by changing the image to helath change... TrollD3 105 — 9y

Answer this question