Gui not tweening properly

So I have this script to tween a gui when a admin or mod announces something

script.Parent.Parent.Visible = false
local frame = script.Parent.Parent
local topBar = script.Parent.Parent.TopBar
local bottomBar = script.Parent.Parent.BottomBar
local tweenTime = 0.5

local noVisible = {}
noVisible.Position = UDim2.new(0.5,0,.488,0)
noVisible.Size = UDim2.new(0,0,.025,0)

local halfvisible = {}
halfvisible.Position = UDim2.new(.31,0,.488,0)
halfvisible.Size = UDim2.new(.379,0,.025,0)

local visible = {}
visible.Position = UDim2.new(.31,0,.25,0)
visible.Size = UDim2.new(.379,0,.5,0)

local barVisible = {}
barVisible.Size = UDim2.new(1, 0, 0.05, 0)

local barNotVisible = {}
barNotVisible.Size = UDim2.new(1, 0, 1, 0)

game.ReplicatedStorage.DisplayGlobalGui.OnClientEvent:Connect(function(message)
	--tween and everything here
	frame.Position = noVisible.Position
	frame.Size = noVisible.Size
	frame.Visible = true
	
	frame:TweenSizeAndPosition(halfvisible.Size, halfvisible.Position, Enum.EasingDirection.In, Enum.EasingStyle.Linear, tweenTime)
	wait(tweenTime)
	
	frame:TweenSizeAndPosition(visible.Size, visible.Position, Enum.EasingDirection.In, Enum.EasingStyle.Linear, tweenTime)
	wait(tweenTime)
	
	script.Parent.Text = message
	for i=1,0,-0.1 do
		script.Parent.TextTransparency = i
		script.Parent.Parent.TitleText.TextTransparency = i
		script.Parent.Parent.PoppinLogo.ImageTransparency = i
		wait()
	end
	wait(5)
	for i=0,1,0.1 do
		script.Parent.TextTransparency = i
		script.Parent.Parent.TitleText.TextTransparency = i
		script.Parent.Parent.PoppinLogo.ImageTransparency = i
		wait()
	end
	
	frame:TweenSizeAndPosition(halfvisible.Size, halfvisible.Position, Enum.EasingDirection.In, Enum.EasingStyle.Linear, tweenTime)
	wait(tweenTime)
	
	frame:TweenSizeAndPosition(noVisible.Size, noVisible.Position, Enum.EasingDirection.In, Enum.EasingStyle.Linear, tweenTime)
	wait(tweenTime)
	
	script.Parent.Parent.Visible = false
end)

However sometimes it tweens properly (shown below)

And sometimes it does this

I am not sure why it does this, does anyone know? Is it a problem with my code or roblox?
Also, there are no errors when it fails to tween properly

I believe it is because of wait(tweenTime). The thing is, the Tween can actually take a little bit more than tweenTime to finish since the time it was called, so there are two options you could do:

  1. change “wait(tweenTime)” to wait(tweenTime + .1) or something small like that.
  2. Set the second tween as a Callback to the first tween, meaning the script will run the second tween right when the first one ends.

I believe this should be the issue with your script, so let me know if this fix works or not.

I will try that, do you think setting tween override or something like that would work too? (the variable you declare after the time)

Oh yeah, if you set them to “true” then the second tween will just override the tiny amount of tweeting first one has left to do, so that might work. Give it a try and check it out.