Every time health changes do

Hello,
I was wondering if someone could tell me what I would need to do to make it so whenever a player’s health gets lower and lower the screen, for example, would get darker. I’ve been stuck on where to start for a bit now. I’m not asking for someone to post some code but if someone could tell me what to look up on the wiki or something that’d be great.

1 Like

so in a local script you would find the humanoids health, and then detect if it got lower and adjust the transparency of a frame(that fits the whole screen. Sorry if this is complicated but ill gladly help if you need any.

1 Like

The first question is how do you want to make the screen darker? You could use a GUI frame that is black, that gets less and less transparent as their health decreases. You could also just make the Brightness property of the Lighting drop as their health drops.

Either way, tie a function to the Humanoid.HealthChanged event. If the health is less than it was last time the health was changed, then change the darkness respectively (if you use a GUI frame, maybe match the percentage of health to the percentage of transparency out of 1, or if its brightness, out of whatever you want the max brightness to be.

Edit: You probably will want to change the brightness/transparency regardless if the health increased or decreased, since otherwise their screen would stay black even if they healed afterwards.

3 Likes

OH!

match the percentage of health to the percentage of transparency out of 1

That’s what I need to do, I guess I was just thinking too hard lol. Thanks for the help :slight_smile:

1 Like

going off @Hazania’s idea of using a full-screen gui that darkens as the player’s health changes

local humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local dimgui = --path here
humanoid.HealthChanged:Connect(function()
    local percent = humanoid.Health/humanoid.MaxHealth
    dimgui.Transparency = percent
end)
2 Likes