Would it be possible to reverse a value?

Hey again devs,
i have a quick question as it may help me in what i’m trying to achieve here.

Basically let’s say you have some type of value that can increase and decrease at a minimum of 0 and 1.

Now if you would set for example a part’s Transparency to this value it would be transparent at 1 and visible at 0.

Would it be possible to reverse this math? What i mean with reverse is if the value is at 0 the part would be transparent and if its at 1 then it would be visible.

I’m not talking about if statements by the way. As i would like the number to also go in between 0 and 1.

Any help would be appreciated.

I got an idea. What if you do 1 - Transparency = Reversed transparency. Example 1: 1 - 0.4 = 0.6.
Example 2: 1 - 0 = 1

2 Likes
local transparency = 0;

transparency = transparency == 0 and 1 or 0 -- switches between 0-1 depending on the current value
2 Likes

i’ll try this out, give me a second and ill be back to you

Not exactly what i am trying to achieve here, the value of transparency could also change into decimals (aka between 1 or 0).

Would you like it to always move between from 0 to 1 OR 1 to 0?

1 Like
local Part = game.Workspace.Part
local CurrentTransparency = Part.Transparency
Part.Transparency = (1 - CurrentTransparency)
1 Like

From 0 to 1, to be more specific i am trying to match the PlaybackLoudness of a sound to the TextTransparency. I just realized that the PlaybackLoudness will actually end up as 0, so the TextTransparency would just be visible.

You can change the 1 to the max amount that the value can hold. I don’t know if this works if the value uses negative numbers tho.

1 Like

Read the post above, i made a mistake by making this post as i already got it working. Sorry about that

Well you could just then do percentage counting with playbackLoudness / maxPlaybackLoudness which returns value between 0-1.

1 Like

It’s fine! Good luck with your project.

1 Like

I am indeed doing that, it just looked weird at first so i thought there was something going wrong.

1 Like

I’ll give this post the Solution as it basically is the way i’m doing it. Thanks for all!

1 Like

Yeah it probably will look weird at first, since you can’t really get the maximum value of PlaybackLoudness, so you have to move it up slowly.

1 Like

Exactly yeah, i’ll expirement with it more. Again thanks for all

1 Like

What if, lets say I’m trying to make an ammo counter and as you loose ammo the image becomes more transparent/invisible.

I have a max ammo count and a current ammo count

ammoIcon.ImageTransparency =  currentAmmo/maxAmmo

but this makes the image transparent at the start and makes it less transparent. I’m aware as to why but I need to know how to make it do the opposite.

You substract the percentage from 1, which will make it reverse.

1 - (currentAmmo / maxAmmo)

Oh my gosh, I feel so stupid now.

Such a simple answer!

Thank you for the help! :slight_smile:

1 Like