How can I change color depedent on health = darker color

I want to change a parts color but depending on the parts “health”

I have a part with a maxhealth and health value in it. I want to change the RGB color in a script depending on the maxhealth, health, and number 255. Only the problem is I am terrible at math and don’t know how to make this work/

1 Like

In what way do you want the colors to change?

1 Like

I want the color of the part the player is mining to get darker until it is black

this is one block

you should look into ColorSequence’s it seems like it would solve your issue

1 Like

I dk how to change color still,

1 Like

the only thing I need is math right now I have this

while wait(.2) do
	if HoldingMB1 == true then
		local t = Mouse.Target
		
		if t then
			if t:HasTag("Mineable") then
				local Damage = 1-t:FindFirstChild("Toughness").Value
				local Health = t:FindFirstChild("Health")
				
				game.ReplicatedStorage.MineHandler:FireServer({Action = "Destroy",Part = t,Health = Health,Damage = Damage})
				Health.Value-=Damage
				
				local MaxHealth = Health:FindFirstChild("MaxHealth").Value
				
				local DefaultColor = t.DefaultColor.Value
				
				--t.Color = Color3.fromRGB(DefaultColor.R-255/(Health.Value*255),DefaultColor.G,DefaultColor.B)
				
				if Health.Value<=0 then
					t.Transparency = 1
				end
				
			end
		end
	end
end

commented out conde is the part I tried trying to create bu thte math was worng it turned black instantly

script.Parent.Color = Color3.new(1,1,1)
script.parent being the part

it must depending on current health

dont use wait, wait is dated, use task.wait

just watch for the health changing with .Changed?

the script is client script in startplayerscript and I have holdingmb1 bool thats true when it being helding

so the client fires remoteevent that changed health but I’m changing color locally and idk hwo

I mean I do know hwo to change color but idk how to change it depending on getting

lower healt = darker color

dont subtract it by 255, remove -255

(anything devided by zero is undefined (or 0 in luau)

yes but then it must only be the daafault color and lower health = it gets darker

I did this a different wayghjghjfgjdftj

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.