Increase GUI opacity when near a part

Hi, I’m making a sort of system that indicates proximity to an object.
Essentially, the effect I’m trying to achieve is a GUI that becomes more visible the closer the player is to a certain part, I was thinking of using tweens but I’m not sure if it’d be feasible in this particular case.

I came up with a REALLY crude script that does the job (kind of) but it’s not really smoothed out and that’s the main thing I want to get here, make it more opaque as the player gets closer

local runService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer

local GUI = script.Parent
local static = GUI.ImageLabel

local triggerPart = game.Workspace.ExitRoom.ExitDoor.DoorPart

runService.RenderStepped:Connect(function()
	if player:DistanceFromCharacter(triggerPart.Position) < 30 then
		static.ImageTransparency = 0.75
	end
end)

As I mentioned, I’m trying to see if I can use tweening or possibly :Lerp() but I am not sure if it’s possible.

Any help is appreciated, thank you in advance

Hi, If I have understood what you are trying to do, tween is not necessary.
This might help.
that’s the main thing I want to get here, make it more opaque as the player gets closer

local ui = script.Parent.ImageLabel
local v1 = game.Workspace.ExitRoom.ExitDoor.DoorPart
RunService.RenderStepped:Connect(function()
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").MoveDirection.Magnitu > 0
ui.Transparency = (player:DistanceFromCharacter(triggerPart.Position))/100 -- change "100" according your needs
end
)
2 Likes