Tweening Billboard gui's

Hello Developers,

I am trying to make a local script that tweens all billboard GUIS when the player is in a certain range.

I chose to loop through all the billboard guis in the game every heartbeat. I’m a bit concerned about performance and I just wanted to make sure that the local script I made for this wouldn’t cause any issues performance-wise.

If there are any, please give feedback!

local RunService = game:GetService("RunService")

local maxDistance = 15

RunService.Heartbeat:Connect(function()
	for i, v in pairs(script.Parent:GetDescendants()) do
		if v:IsA("BillboardGui") then
			local distance = (v.Adornee.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
			if distance >= maxDistance then
				v.Enabled = false
				--tween here
			else
				v.Enabled = true
				--- tween here
			end
		end
	end
end)```

Maybe I’m wrong but why are you doing this? There is already a built in feature to disable the ui billboard

Hello,
There is one, however, you can’t tween it or listen for when it happens which is why I made this script

what are you trying to tween? (transparency, position, size, …)

I’m attempting to tween the size and make it pop up rather than the default one that Roblox gives which is just visible and not visible

this should work (didnt tested it so it might have bugs)

task.wait(1)

local guisGroup = script.Parent

local sizes = {}
local guis = {}


for i,gui in pairs(guisGroup:GetDescendants()) do
	if gui:IsA("BillboardGui") then
		table.insert(guis,gui)
		table.insert(sizes,gui.Size)
	end
end


local maxDistance = 15


local function popUp(gui,size)
	
	gui:TweenSize(
		UDim2.new(size.X, size.Width, size.Y, size.Height), --endSize
		Enum.EasingDirection.Out,    -- default
		Enum.EasingStyle.Elastic,      -- easingstyle
		5,                          -- time
		true                      -- I set it just incase there is another tween happening
	)
	
end


local function hide(gui,size)

	gui:TweenSize(
		UDim2.new(0, 0, 0, 0), --endSize
		Enum.EasingDirection.Out,    -- default
		Enum.EasingStyle.Elastic,      -- easingstyle
		5,                          -- time
		true                      -- I set it just incase there is another tween happening
	)

end


game["Run Service"].Heartbeat:Connect(function()
	for i, gui in pairs(guis) do
		
		local distance = (gui.Adornee.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
		
		if distance >= maxDistance and gui.Enabled == true then
			gui.Enabled = false
			hide(gui,sizes[i])
		elseif distance < maxDistance and gui.Enabled == false then
			gui.Enabled = true
			popUp(gui,sizes[i])
		end
		
	end
end)

basically what it does is to store all the guis in a table as first, then everytime checks for every gui in the table if they’re too far or not

2 Likes

Thank you, but I wasn’t looking for a way to make it, I just was wondering if my code was the best method to go about the task!

well, I’ve maked sure the script has better performance (instead of doing the loop trough every single descandant of the group every frame of the game, it just stores all guis in one table at the start of the game (this will make sure the script runs smoothly), then it checks if the gui has alredy been enabled or not, so it wont do the tween everytime).

Awesome, thanks for the help! (char limit)

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