Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a light dim as your health decreases?

How would I even begin to make this? I currently have a light inside of the HumanoidRootPart of my startercharacter, and I'd like it to dim as the Humanoid's health decreases. Reaching zero, just as the Entity dies. Any help is much appreciated^^

1 answer

Provided your MaxHealth is 100, you could take the Min and Max 'Range' of the Light and just decrement it dependant on the Health of the Player compared to the max health.

Place this ServerScript in StarterCharacter.

local Player = script.Parent
local Humanoid = Player:WaitForChild("Humanoid")

local Light = Player.HumanoidRootPart.Light
local lightMax = 32
local lightMin = 0

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	Light.Range = (lightMax - lightMin) * (Humanoid.Health / Humanoid.MaxHealth) + lightMin
end)

If you have any questions feel free to ask- I can't actually test this as ROBLOX is down but it should work fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.