Difficulty with tweening

Hi, I am trying to make a ‘find the’ game and am having some trouble with tweening on some of the Guis. The way it should work is when you find a new thing and touch it, the Gui tweens in, which it does do perfectly. However, when you click the close button, it should repeat exactly how it tweened in but in reverse. This worked perfectly before I changed the tween a bit to try and make it smoother, however after these changes when I click the close button nothing happens.

Does anyone know how to fix this and make it so that the tween plays (either what I’ve done wrong & what I need to do to fix it or a working version of the script), I’ve tried YouTube and ChatGPT but neither have helped.

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local TweenService = game:GetService("TweenService")
local thing = script.Parent
local badgeID = 4160908119134917

local collectSound = workspace.Music.soundEffects.thingCollect
local errorSound = workspace.Music.soundEffects.alreadyHave

local popupActive = false
local lastNotificationTime = 0
local notificationCooldown = 3
local tweenInProgress = false

local function onTouched(otherPart)
	local player = Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
		local playerGui = player:FindFirstChild("PlayerGui")

		if BadgeService:UserHasBadgeAsync(player.UserId, badgeID) then
			local currentTime = tick()

			if not popupActive and (currentTime - lastNotificationTime) >= notificationCooldown then
				lastNotificationTime = currentTime
				if playerGui then
					local notificationGui = playerGui:FindFirstChild("NotificationGui")
					if notificationGui then
						local notificationLabel = notificationGui:FindFirstChild("notificationLabel")
						if notificationLabel then
							notificationLabel.Visible = true
							errorSound:Play()

							wait(2)
							notificationLabel.Visible = false
						end
					end
				end
			end
		else
			-- Awards the badge + notification
			BadgeService:AwardBadge(player.UserId, badgeID)
			collectSound:Play()

			-- Shows the message
			if playerGui then
				local popUpGui = playerGui:FindFirstChild("ThingFoundGui")
				if popUpGui then
					local thingName = thing:FindFirstChild("thingName").Value
					local thingImageId = thing:FindFirstChild("thingImage").Value
					local thingFoundFrame = popUpGui.ThingFoundFrame

					thingFoundFrame.thingNameText.Text = "You found " .. thingName .. "!"
					thingFoundFrame.thingImageLabel.Image = thingImageId
					popUpGui.Enabled = true
					popupActive = true

					-- Tweening
					thingFoundFrame.Size = UDim2.new(0, 0, 0, 0)

					local thingImageLabel = thingFoundFrame.thingImageLabel
					local thingNameText = thingFoundFrame.thingNameText

					thingImageLabel.Size = UDim2.new(0, 0, 0, 0)
					thingNameText.Size = UDim2.new(0, 0, 0, 0)

					if not tweenInProgress then
						tweenInProgress = true  -- Marks the tween as in progress
						local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

						local goalFrame = {Size = UDim2.new(0, 860, 0, 605)}
						local goalImageLabel = {Size = UDim2.new(0, 404, 0, 404)}
						local goalNameText = {Size = UDim2.new(0, 852, 0, 79)}

						local tweenFrame = TweenService:Create(thingFoundFrame, tweenInfo, goalFrame)
						local tweenImageLabel = TweenService:Create(thingImageLabel, tweenInfo, goalImageLabel)
						local tweenNameText = TweenService:Create(thingNameText, tweenInfo, goalNameText)

						-- Opening tweens
						tweenFrame:Play()
						tweenImageLabel:Play()
						tweenNameText:Play()

						tweenFrame.Completed:Wait()
						tweenImageLabel.Completed:Wait()
						tweenNameText.Completed:Wait()

						tweenInProgress = false
					end

					local closeButton = popUpGui.ThingFoundFrame.closeButton

					closeButton.MouseButton1Click:Connect(function()
						print("Close Clicked")
						if not tweenInProgress then
							tweenInProgress = true
							local closeTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

							local closeGoalFrame = {Size = UDim2.new(0, 0, 0, 0)}
							local closeGoalImageLabel = {Size = UDim2.new(0, 0, 0, 0)}
							local closeGoalNameText = {Size = UDim2.new(0, 0, 0, 0)}

							local closeTweenFrame = TweenService:Create(thingFoundFrame, closeTweenInfo, closeGoalFrame)
							local closeTweenImageLabel = TweenService:Create(thingImageLabel, closeTweenInfo, closeGoalImageLabel)
							local closeTweenNameText = TweenService:Create(thingNameText, closeTweenInfo, closeGoalNameText)

							-- Close tween
							closeTweenFrame:Play()
							closeTweenImageLabel:Play()
							closeTweenNameText:Play()

							closeTweenFrame.Completed:Wait()
							closeTweenImageLabel.Completed:Wait()
							closeTweenNameText.Completed:Wait()

							-- Disable
							popUpGui.Enabled = false
							popupActive = false
							tweenInProgress = false
						end
					end)
				end
			end
		end
	end
end

thing.Touched:Connect(onTouched)
1 Like

could you give a video or picture?

maybe because you have to manually set the position back