# How can I convert rgb alpha color value to roblox transparency?

I tried to divide the alpha value by 255 and it didn’t worked(25/255)
I secondly tried to to divide 255 by 25 and it didn’t worked (255/25) and it didn’t worked

# so what do I need to do

2 Likes

I don’t understand what you are trying to do. Roblox uses RGB for colors. Are you trying to change the transparency based on the color?

1 Like

Color3.fromRGB(Red, Green, Blue). It is already built-in as @XdJackyboiiXd21has said.

1 Like

I am trying to convert the alpha value of a RGBA color(244, 209, 13, 255)). in this example it’s 255. What I want is to convert the 255 value to a brick transparency value

1 Like

Then try to do something like this:

``````local AlphaValue = 255

Part.Transparency = AlphaValue/255
``````
2 Likes

I only want to convert the transparency. I don’t care about the color

1 Like

Forgot to post a new message, but there.

1 Like

Oh I see. Transparency goes from 0 - 1, so I would divide the last value by 255. We will get a long decimal so lets round it using the following: Multiply that number by 100 and use math.Floor(number + 0.5) to round the number, then divide back by 100.

For Example: lets say the 4th value was 122. 122/255 is approximately 0.47843, this is to long. Multiply it by 100 to get 47.843. Then we say math.Floor(47.843+0.5). Roblox will then round this number to 49. Finally we divide that number by 100 and we get a transparency of 0.49.

Code:

``````local function findTransperancy(number)
local transperancyvalue = math.Floor(number/100 + 0.5) * 100
print(transperancyvalue)
end

findTransperancy(100) --call the function with the 4th value
``````

I have to go, I hope that helps. Good luck with your problem!

1 Like

Both methods can work with @XdJackyboiiXd21’s method rounding the Alpha value if you don’t want the decimal to be extremely long. But if you prefer the transparency being approximate as possible all the way to the last decimal digit, you can use the method I have shown you above.

PS: Make sure to modulize his function if you prefer it. Only just in-case if you’ll use it in other scripts.

2 Likes

here’s this adapted into a module

``````local function alphaToRblxTransparency(alphaVal)
return alphaVal/255
end

return { alphaToRblxTransparency }
``````
1 Like

Perfect. The function will be able to be executed like this:

``````local alphaValue = module.alphaToRblxTransparency(255)

Part.Transparency = alphaValue
``````
1 Like

I dont wanna be nitpicky, but that’s an array. So you would need to call the function like this…

``````local alphaValue = module[1](255)
Part.Transparency = alphaValue
``````
2 Likes

it’s just me being me who’s used to typescript syntax

I’m so used to using dictionaries lol. Screwed up on my end.