Stopping a tween

I just realised i don’t see a line to reset the Adornee and Enabled properties myself lol

please print which is the nearest egg because I think thats the bug

Getting the closest egg works, I also tried to stop the coroutine but that didn’t work either:

local closeCoroutine

function module.TweenOpen()
	print("open")
	
	if closeCoroutine then
		print("stop tween")
		coroutine.close(closeCoroutine)
		closeCoroutine = nil
	end

	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
	local tween = TweenService:Create(EggDisplayGui.MainFrame.UIScale, tweenInfo, {Scale = 1})
	tween:Play()
end

function module.TweenClose()
	print("close")

	local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	local tween = TweenService:Create(EggDisplayGui.MainFrame.UIScale, tweenInfo, {Scale = 0})
	tween:Play()
	
	closeCoroutine = coroutine.create(function()
		tween.Completed:Connect(function()
			print("done")
			EggDisplayGui.Enabled = false
			EggDisplayGui.Adornee = nil
		end)
	end)
	
	coroutine.resume(closeCoroutine)
end

Watching it closely it seems to glitch out when calling the Open function while the Close one is working and it just fires .Completed for whatever reason??, try changing the Adornee and Enabled from whitin the Open function see if that causes a different behavior

The tween.Completed would still run after stopping the tween.

Its actually because the tween takes 3 seconds to finish (for testing).

put it in the open func. its safer

Wait i think i got an idea, so once it runs the close function it will wait for tween.Completed from the tween variable, so whenever a tween is completed it fires the completed event (i think that’s what’s going on)
perhaps try task.wait(tween.Length) and then disabling the GUI, instead of tween.Compleated:Connect()

But that would still give the same result.

The only downside of that that i can see is that it’s on a Heatbeat event so it’s resetting every frame

But it would only run once since I have thing part:
if nearestEgg and not NearestEgg.Value then

Try removing the part where you set the adornee and enabled to false/nil.

I think thats the solution
oh and I would connect it to prerender

No because tween.Completed is running from outside the scope of the closing function, so even if uncalled it will run, meanwhile task.wait() doesn’t connect anything and will only run after the function is called

It works but I don’t want it to be visible after it closes.

You could be kinda hacky with it and put it on a very far part from the player’s character (somewhere they will never end up at) and lower the max distance from where it can be seen

use

tween.Completed:wait() 
--code
1 Like
local tween
local tween1

function module.TweenOpen()
	print("open")
if tween1 then
tween1:Cancel()
tween1 = nil
end
gui.Visible = true
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
	 tween = TweenService:Create(UIScale, tweenInfo, {Scale = 1})
	tween:Play()
end

function module.TweenClose()
	print("close")
if tween then
tween:Cancel()
tween = nil
end
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	 tween1 = TweenService:Create(UIScale, tweenInfo, {Scale = 0})
	tween1:Play()

	tween1.Completed:Connect(function()
		gui.Visible = false
	end)
end

I have tried this but it didn’t work.

Didn’t work:

local closeTween

function module.TweenOpen()
	print("open")

	if closeTween then
		closeTween:Pause()
		closeTween = nil
	end

	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
	local tween = TweenService:Create(EggDisplayGui.MainFrame.UIScale, tweenInfo, {Scale = 1})
	tween:Play()
end

function module.TweenClose()
	print("close")

	local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	closeTween = TweenService:Create(EggDisplayGui.MainFrame.UIScale, tweenInfo, {Scale = 0})
	closeTween:Play()

	closeTween.Completed:Wait()

	EggDisplayGui.Enabled = false
	EggDisplayGui.Adornee = nil
end