I was writing a small function for showing/hiding some beam and its endpoint Part, and figured out something that I think deserves mentioning:
You can micro-optimize memory and make your code a bit more terse (though readability could depend on how you write it) by storing original .Transparency values as the decimal part of the transparency.
This is because .Transparency unintuitively accepts numbers less than 0 and greater than 1, for some reason.
Parts Example
You have a collection of parts with transparencies 0.1, 0.3, 0.21, 0.67, 0.69, 0.42, yada yada yada… You want to write a function that hides and unhides them using their transparencies. I’d think that someone might intuitively tackle this problem by storing the original transparencies above in an Attribute or somewhere else in the code. But, you could actually just store them in the decimal portion of your transparencies by adding 1 to each transparency.. then subtracting 1 when you want the parts unhidden! And, if you’ve come across any transparent parts, they’ll still be transparent!
So, if you wanted to loop through a group of objects with some sort of .Transparency property (or something that behaves similarly in that it shares the oddity I described above), you can try implementing something like this hide/show function I wrote below:
local function toggle_indicator(shown)
Arrow.End.Transparency += (if shown then 0 else 1) - math.floor(Arrow.End.Transparency)
Arrow.Beam.Enabled = shown
end
I like writing terse code.. aaaand this could definitely be made more readable
. But I decided to share this little trick I found when trying to save my time writing extra lines (and the trivial amount of extra memory I’d use).
Please note that this is code for a project I’m working on, and is not generalized at all lmao. It’s up to you to implement this random trick I’m sharing.
For some reason, coming across this neat trick (though using a very obvious fact that .Transparency > 1 is possible) in my toggle_indicator function felt really beautiful, though trivially terse. I thought it wasn’t intuitive enough for developers for me not to make this a small gem. ![]()