How will I get around making a script for the transparency to decrease upon getting close to a part?

You can write your topic however you want, but you need to answer these questions:
I am working on a creation game, but I need to make barriers that become less transparent when you get closer to them

Here is an illustration describing what I am looking for:

I looked far and wide through the devforum, I have not found anything like this, but I am aware there is something a lot of math behind calculating the distance between two points.

1 Like

Well I mean you could just use raycasting or magnitude, loop it and add if statements in between to see the distance and adjust transparency that way.

laughs in magnitude

anyways just find the magnitude of the player’s HumanoidRootPart and the Transparency changing part, then you can change transparency based off the magnitude

1 Like

This is what I was looking for, I saw magnitude in a post but forgot the word within seconds

(I have the memory span of a gold fish)

You only really need three things: DistanceFromCharacter, Transparency (or LocalTransparencyModifier if preserving the transparency is important - this would be a better option for your system) and Heartbeat. I prefer DistanceFromCharacter over magnitude because if the structure of the character ever changes, you never need to change your own code, it’ll get updated on the backend.

Heartbeat is what you use to run code every frame. DistanceFromCharacter is self explanatory as is transparency. Put those three together and you can work out a system for this.

1 Like

All character models require a humanoidrootpart > So it wouldn’t matter if the character changes because it’ll still need a humanoidrootpart. Roblox’s system doesnt let rigs operate without one.

yep also just so you know magnitude is one of the many options you can try
@colbert2677 and @Ryuunske talk about other options beside magnitude

choose whichever one you feel like would be the best fit

Believe it or not, HumanoidRootPart didn’t always exist. Suppose DistanceFromCharacter existed before HumanoidRootPart did and root parts became standard for working with character positions (before in 2010, we were conditioned to use Torso or Head). Now you have a lot of code to change.

DistanceFromCharacter would update on the backend to change from, say, checking the position from the Head to the HumanoidRootPart (which, AFAIK, is exactly what happened). Anyone using DistanceFromCharacter to check the position between a character and a vector point wouldn’t have to change any code, it would automatically account according to the HumanoidRootPart.

I use DistanceFromCharacter to future-proof my code.

I do not know if LocalTransparencyModifier also applies to Texture instances.

Decals also have a LocalTransparencyModifier (and by extension Textures do as well because Textures inherit from the Decal class).

btw thanks for showing this, even though I will probably never use it, it is cool to see how you can mess with transparency in more ways

I know it used to never exist, believe me I’m well aware. I was scripting during that time. HumanoidRootPart will never be removed so there’s really no reason to not use it > roblox literally said its making its system compatible with all old roblox rigs > meaning no matter how advanced the site gets r6 will still be around and so will humanoidrootpart c:

That’s fine. I use it to future-proof my code in case the structure ever changes. I don’t trust Roblox with any sorts of guarantees and there may be more idiomatic practices in the future to which DistanceFromCharacter will receive updates without me having to change it manually.

HumanoidRootPart is just as safe to use for magnitude checks, but I sure love my function. Bonus points for the way it looks in my code: nice, readable and explicit. Just one vector point and all the calculations are done for me by the engine.

What are you gonna do when the deprecate distancefromcharacter then lmao

you two should take the conversation to dms/pms

1 Like

You’re right, its off topic I apologize

All I wanted is to probably learn something about remote events but I just made twitter in one thread

no no it’s fine, chat has cooled down now :sweat_smile:

I think it’s fine to discuss on the thread. It is slightly off topic but really there’s no need to break down my stance this hard. Support threads are good for offering and discussing advice, so as long as it stays constructive and on topic it’s fine. If it’s really that bad, you can flag it instead I guess - this should be done over calling it out on the thread because then that post too is off topic.

@Ryuunske I have faith they won’t deprecate it, don’t worry. Deprecation only happens for things that can’t and shouldn’t be supported anymore. No reason why this would reach that stage.

I wasn’t trying to make it sound harsh sorry
still pretty new to this forum and the word “off-topic” is just all over the place because it’s so strict sometimes, I just need to get used to the forum a bit more