So when getting close to a part and then going far back and go close again, the close tween would still be playing and the gui would be disabled:
function module.TweenOpen()
print("open")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(UIScale, tweenInfo, {Scale = 1})
tween:Play()
end
function module.TweenClose()
print("close")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
local tween = TweenService:Create(UIScale, tweenInfo, {Scale = 0})
tween:Play()
tween.Completed:Connect(function()
gui.Enabled = false
gui.Adornee = nil
end)
end
I have tried to wrap a coroutine and to close the coroutine when the module.TweenOpen() runs and also tried to create a variable at the start of the script called “tween” but that didn’t work either.
You could have a variable for the tween that is playing and when the function is called check if there is a tween already if so cancel that one and set the current tween to nil, and set it to nil to on the .Completed event
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local Eggs = workspace:WaitForChild("Eggs")
local EggDisplayGui = script:WaitForChild("EggDisplayGui")
local EggDisplayModule = require(script:WaitForChild("EggDisplayModule"))
local NearestEgg = script:WaitForChild("NearestEgg")
RunService.Heartbeat:Connect(function()
local nearestEgg, nearestDistance = EggDisplayModule.GetNearestEgg()
if nearestEgg and not NearestEgg.Value then
NearestEgg.Value = nearestEgg
EggDisplayGui.Adornee = nearestEgg.PrimaryPart
EggDisplayGui.Enabled = true
EggDisplayModule.TweenOpen()
elseif not nearestEgg and NearestEgg.Value then
NearestEgg.Value = nil
EggDisplayModule.TweenClose()
end
end)