Tween.complated not working

I got this issue where this notification won’t delete from a notification list after waiting for the tween to finish so instead of using a wait I used a tween.completed but it still doesn’t work. The mouseButton1click also does not fire when I click on it even though the notification is still in the list.

function notification.new(text, Type, length)
	local newNotification = Notification:Clone()
	newNotification.Label.Text = text
	newNotification.Fill.BackgroundColor3 = notification.Types[Type].Color
	newNotification.Parent = NotificationList
	
	newNotification:TweenSize(UDim2.new(1, 0,0.308, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, .1, false)
	
	task.spawn(function()
		print("spawned")
		local tween = TweenService:Create(newNotification.Fill , TweenInfo.new(length), {Size = newNotification.Fill.Size - UDim2.new(1,0,0,0)})
		print("tween")
		tween:Play()
		print("playing")
		task.wait(length)
		print("done waiting")
		
		tween.Completed:Connect(function()
			print("its done")
			newNotification:TweenSize(UDim2.new(1, 0, 0, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.1, false)
			task.wait(0.1)
			print("deleted")

			if newNotification then
				newNotification:Destroy()
				print("destroyed")
			end
		end)
	end)
	
	newNotification.Button.MouseButton1Click:Connect(function()
		print("pressed")
		newNotification:TweenSize(UDim2.new(1, 0, 0, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, .1, false)
		task.wait(0.1)
		
		if newNotification then
			newNotification:Destroy()
		end
	end)
	
	if Type == "Success" then
		script.Parent.Parent.SpeedRaised:Play()
	end
end
1 Like

tween.Completed is not being fired because you are waiting the length of the tween before connecting to the event. Removing task.wait(length) should fix this.

As for the mouse event not working, do you viewing posting the output to see if there are any errors?

2 Likes

That doesn’t fix it, the script only goes as far as print("playing") and nothing happens. The mouse event doesnt work and doesnt print with no errors

1 Like

instead of tween.Completed:Connect(function) insert tween.Completed:Wait()

Sory my english im use translator

1 Like

Perhaps it’s finishing before connecting, move the tween:Play() to be under this block of code:

tween.Completed:Connect(function()
	print("its done")
	newNotification:TweenSize(UDim2.new(1, 0, 0, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.1, false)
	task.wait(0.1)
	print("deleted")

	if newNotification then
		newNotification:Destroy()
		print("destroyed")
	end
end)

As for the mouse event, make sure the button is Active and Interactable, and try adding some prints around the connection to see if it’s reaching that code.