How do I make it so that a tween does not have to finish for another tween to happen

Script:

local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
local Clone = GUI:Clone()
Clone.Parent = Prox

Prox.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	Clone.Parent = Player.PlayerGui
	local Tween = Clone.Image:TweenPosition(UDim2.new(-0, 0, 0.890, 0),"Out", "Sine", 1)
	Prox.TouchEnded:Connect(function(hit2)
		if hit == hit2 then
			local Tween2 = Clone.Image:TweenPosition(UDim2.new(-0, 0, 1, 0),"In", "Sine", 1)
		end
	end)
end)

The title explains it all

1 Like

The fifth parameter of the GuiObject:TweenPosition function can be set to a bool to determine if the tween should override a tween in progress.

local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
local Clone = GUI:Clone()
Clone.Parent = Prox

Prox.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	Clone.Parent = Player.PlayerGui
	local Tween = Clone.Image:TweenPosition(UDim2.new(-0, 0, 0.890, 0),"Out", "Sine", 1, true)
	Prox.TouchEnded:Connect(function(hit2)
		if hit == hit2 then
			local Tween2 = Clone.Image:TweenPosition(UDim2.new(-0, 0, 1, 0),"In", "Sine", 1, true)
		end
	end)
end)

I changed it to this…

local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
local Clone = GUI:Clone()
Clone.Parent = Prox

Prox.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	Clone.Parent = Player.PlayerGui
	local Tween = Clone.Image:TweenPosition(UDim2.new(-0, 0, 0.890, 0),"Out", "Sine", 1, true)
	Prox.TouchEnded:Connect(function(hit2)
		if hit == hit2 then
			if Tween then
				local Tween2 = Clone.Image:TweenPosition(UDim2.new(-0, 0, 1, 0),"In", "Sine", 1)
			end
		end
	end)
end)

Is this what you mean?

Yes.

This text will be blurred

it still does not work for some reason.

You forgot the other tween, both should be able to override one another.

local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
local Clone = GUI:Clone()
Clone.Parent = Prox

Prox.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	Clone.Parent = Player.PlayerGui
	local Tween = Clone.Image:TweenPosition(UDim2.new(-0, 0, 0.890, 0),"Out", "Sine", 1, true)
	Prox.TouchEnded:Connect(function(hit2)
		if hit == hit2 then
			if Tween then
				Tween = nil
				Tween = Clone.Image:TweenPosition(UDim2.new(-0, 0, 1, 0),"In", "Sine", 1, true)
			end
		end
	end)
end)

what does this part do
blank space