Billboards getting dimmer

I need a script that makes a billboard GUI image gets dimmer as you go farther away from them.

Use the game:GetService("RunService").RenderStepped event to run a function every frame, which checks the distance between the camera and the GUI’s part, and sets the transparency based on that (maybe using a formula like math.clamp(distance / maxDistance, 0, 1))

1 Like

Use raycasting to get the distance of the player to the billboard and have a light source behind the billboard so depending on the raycast result you change the intensity of the lighting.

1 Like

what do you mean by dimmer?
or something completely different?

1 Like

I don’t know how to use raycasting

I mean that as you go farther away the billboard GUI gets more transparent

I basically made this by using a RenderStepped function and calculating the distance between the player and the BillboardGui to calculate the transparency I need.

image

--[[ Local Script ]]--
local RunSerivce = game:GetService("RunService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

local BillBoardGui = script.Parent
local Frame = BillBoardGui.Frame

local maxDistance = 80
local minDistance = 40

RunSerivce.RenderStepped:Connect(function()
	local character = localPlayer.Character
	if not character then return end
	if not BillBoardGui.Adornee then return end
	
	local billboardWorldPosition = 
		(BillBoardGui.Adornee:GetPivot() * CFrame.new(BillBoardGui.StudsOffsetWorldSpace)).Position + BillBoardGui.StudsOffset
	
	local distance = (billboardWorldPosition - character.HumanoidRootPart.Position).Magnitude
	Frame.Transparency = math.clamp((distance - minDistance)/(maxDistance - minDistance), 0, 1)
end)
1 Like

I tried this in a LocalScript and it didn’t work.

This is how I setup my workspace: 2023-10-22 12-16-36. I should note that this is just a template on how to do it, you have to make it work for your own system. Some key things to note: make sure that the LocalScript is a direct descendant to the BillboardGui and that the frame that you want to become transparent should be named Frame, which is also a direct descendant to the BillboardGui.

1 Like

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