Make Part Fade Over Distance

I believe what I’m asking is relatively simply but I have no idea how to do it. Basically, when I’m far enough away from a part, I want it to disappear. That would be pretty easy, the hard part is I want this part to become more transparent the further I get from it, until it finally disappears.

if (character.Head.Position - part.Position).Magnitude >= 10 then
		--gradually reduce transparency until you get to 20, where it would then be fully transparent.
end

Any help is appreciated! If clarification is needed I’ll be glad to provide.

Just normalize the magnitude to your desired distance.

local DesiredCutoff = 20
local Transparency = math.clamp((character.Head.Position - part.Position).Magnitude/DesiredCutoff, 0, 1)
Part.Transparency = Transparency
2 Likes

This does work, but I also need a minimum distance to where the transparency won’t be changed, in other words it’ll only start to fade when you get far enough. Sorry if I didn’t convey that very well in my post!

local MinDistanceCutoff = 10
local MaxDistanceCutoff = 20

local Distance = (character.Head.Position - part.Position).Magnitude

local Transparency = math.clamp((Distance-MinDistanceCutoff)/(MaxDistanceCutoff-MinDistanceCutoff), 0, 1)

This should probably work

Edit:

Thanks lol, I’m not in studio and testing rn just typing it in my browser.

2 Likes

Are you sure? (Pemdas heheheha)

That seems to work great, thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.