Updating TextLabels on a SurfaceGui every frame causing lag

if Scale.Config.VisualDistanceUnit.Value ~= "Light Years" then
	Billboard.Main.SurfaceGui.MilesFromSun.Text = "(approx. "..FormatNumber(Scale.GetVisualUnit(StudsFromTheSun)).." "..Scale.Config.VisualDistanceUnit.Value.." from the Sun)"
	Billboard.Main.SurfaceGui.MilesFromEarth.Text = "(approx. "..FormatNumber(Scale.GetVisualUnit(StudsFromTheEarth)).." "..Scale.Config.VisualDistanceUnit.Value.." from the Earth)"
	Billboard.Main.SurfaceGui.MilesFromPrimaryBody.Text = "(approx. "..FormatNumber(Scale.GetVisualUnit(BodyMobilizer.Distance)).." "..Scale.Config.VisualDistanceUnit.Value.." from Primary Body)"
else
	Billboard.Main.SurfaceGui.MilesFromSun.Text = "(approx. "..Scale.GetVisualUnit(StudsFromTheSun).." "..Scale.Config.VisualDistanceUnit.Value.." from the Sun)"
	Billboard.Main.SurfaceGui.MilesFromEarth.Text = "(approx. "..Scale.GetVisualUnit(StudsFromTheEarth).." "..Scale.Config.VisualDistanceUnit.Value.." from the Earth)"
	Billboard.Main.SurfaceGui.MilesFromPrimaryBody.Text = "(approx. "..Scale.GetVisualUnit(BodyMobilizer.Distance).." "..Scale.Config.VisualDistanceUnit.Value.." from Primary Body)"
end
Billboard.Main.SurfaceGui.OrbitProgress.Text = "(Orbital Progress: "..OrbitPercentage.."%)"
Billboard.Main.SurfaceGui.OrbitCount.Text = "# of Orbits In Simulation: "..FormatNumber(Body.OrbitsSinceSimulationBegan)
Billboard.Main.SurfaceGui.RotationCount.Text = "# of Rotations in Simulation: "..FormatNumber(TotalRotations)
Billboard.Main.SurfaceGui.RotationProgress.Text = "(Rotational Progress: "..RotationPercentage.."%)"
Billboard.Main.SurfaceGui.StudsFromSun.Text = StudsFromTheSun.." Studs from the Sun"
Billboard.Main.SurfaceGui.StudsFromPrimaryBody.Text = BodyMobilizer.Distance.." Studs from Primary Body"
Billboard.Main.SurfaceGui.StudsFromEarth.Text = StudsFromTheEarth.." Studs from the Earth"

For my Solar System Model I am working on bits by bits, I have billboards for each celestial body that updates every frame information about it and it’s position in the simulation. If this becomes any more than like 10 SurfaceGuis it becomes an issue and framerates drop extremely low.

(The provided code runs every RunService.Stepped alongside all of the code responsible for updating the celestial body’s position).

Things I’ve tried:

  • Removing the FormatNumber() method.

Things I will not settle for:

  • Updating it less frequently.

That’s why I’m asking if there is a solution to this!

1 Like

Note: Do not be mistaken by the Billboard variable as this is a Model not a physical Billboard instance.

1 Like

Funnily enough, this is exactly how you fix this issue - is there really a need to update the values every frame?

Now I don’t know exactly how you set up your values, but you could use .Changed events (or something of the sort) to catch when a value has changed, and then update the text whenever it’s fired. You don’t have to change the text every frame that way - you only change text when the value gets changed.

Also consider using less TextLabels/SurfaceGUIs - either hide some that are way too far to be seen, or set your UI up such that it displays multiple stats, rather than dedicating a TextLabel to a single stat.

This won’t work since the values being displayed are not Value Objects provided by Roblox.

I’ll try this, while not as neat or organized, I’ll see if it is a resolution to the issue.

Alright this proved to be worse.