How do I fix the choppiness of my Ui change

I am making a AreaUi, when the player walks into a part which will be named after a place. When the player walks into said part it will display the name of the part. The problem I am having is that the transparency fade is a bit to choppy as it goes frame by frame. I’ve asked multiple people and groups of how to solve this issue but no one has replied so I came to the dev forum as a last chance kind of thing.

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local title = script.Parent.Title
local area = game.Workspace.Area
local toggle = false

while true do wait(1)
	for i, section in pairs(area:GetChildren()) do
		local pos1,pos2 = (section.Position - (section.Size / 2)),(section.Position + (section.Size / 2))
		local region = Region3.new(pos1,pos2)
		local playersfound = game.Workspace:FindPartsInRegion3(region)
		
		for i, playersInArea in pairs(playersfound) do
			if playersInArea:FindFirstAncestor(player.Name) then
				toggle = true
				if title.Text == section.Name then
					
				else 
					title.Text = section.Name
					title.Parent.Enabled = true
					for i = 1,0,-0.1 do
						title.TextTransparency = i
						wait(0.2)
						if i == 0  then
							break
						end
					end
					
					wait(1)
					
					for i = 0,1,0.1 do
						title.TextTransparency = i
						wait(0.2)
						if i == 1 then
							break
						end
					end
				end
			else 
				toggle = false
			end
		end
	end
end

Use a tween :slight_smile:

local tweenTransparency = function(guiObject, targetTransparency, tweenTime)
   local tweenInfo = TweenInfo.new(tweenTime)
   local tween = game:GetService('TweenService'):Create(guiObject, tweenInfo, {Transparency = targetTransparency})
   tween:Play()
   wait(tweenTime) -- Remove if you want
end

For example, you can have this:

local textLabel = script.Parent

tweenTransparency(textLabel, 0, .5) -- First the gui object, then the transparency you want it to be, then how long you want it to take to finish.
-- In this example, it will show the textLabel over a course of .5 seconds :)
1 Like

I don’t use tween’s very much so could you elaborate or explain for me? Like where would I put it and everything?

Just put the function I gave you in any local script that you want and just use the function as showed, it will do all the smooth animations for you :slight_smile:

1 Like

So do I delete my original script?

Not delete everything, just the exact bit of code that you were using to animate the transparency. Replace it with the function :slight_smile:

I think I’m just dumb, I haven’t slept at all today. If you want add me on discord I don’t check the forums often. SlenderMan#6983

I got it to work! But how do I make it fade in and out now? It’s currently just popping up (without a fade in) and isn’t fading out.