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
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?
Color3.fromRGB(Red, Green, Blue). It is already built-in as @XdJackyboiiXd21has said.
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
Then try to do something like this:
local AlphaValue = 255
Part.Transparency = AlphaValue/255
I only want to convert the transparency. I don’t care about the color
Forgot to post a new message, but there.
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!
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.
here’s this adapted into a module
local function alphaToRblxTransparency(alphaVal)
return alphaVal/255
end
return { alphaToRblxTransparency }
Perfect. The function will be able to be executed like this:
local alphaValue = module.alphaToRblxTransparency(255)
Part.Transparency = alphaValue
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
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.