Having undesired delay

Hey, I’ve just been hit with a sudden desire to make a Popup Coin Collection sort of thing - however, there seems to be a HUGE undesired delay between touching the part and the UI appearing; could y’all help me figure out why please?

https://gyazo.com/e0d38dedb5696e1f0a5c12d4bfef1dce.gif

local TweenService = game:GetService("TweenService")

function Touched(Hit)
    if game:GetService("Players"):FindFirstChild(Hit.Parent.Name) ~= nil then
        local Player = game:GetService("Players")[Hit.Parent.Name]
        local Ui = game:GetService("ReplicatedStorage"):FindFirstChild("AddCoinUi"):Clone()
        Ui.Parent = Player.PlayerGui.ScreenGui.Frame
        
        local Position1 = math.random(140,920)
        local Position2 = math.random(109, 403)
        
        Ui.Position = UDim2.new(0,Position1,0,Position2)
        
        local Tween1 = TweenService:Create(Ui, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 1), {["ImageTransparency"] = 0})
        local Tween2 = TweenService:Create(Ui.TextLabel, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 1), {["TextTransparency"] = 0})
        
        Tween1:Play()
        Tween2:Play()
        
        wait(0.6)
        
        Tween1 = TweenService:Create(Ui, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 1), {["ImageTransparency"] = 1})
        Tween2 = TweenService:Create(Ui.TextLabel, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 1), {["TextTransparency"] = 1})
        
        Tween1:Play()
        Tween2:Play()
        
        delay(1.2, function()
            Tween1:Destroy()
            Tween2:Destroy()
            Ui:Destroy()
        end)
    end
end

script.Parent.Touched:Connect(Touched)

To get that gif to actually work I had to increase the “wait(0.6)” to “wait(10)” and the “delay(1.2)” to “delay(12)”.

Try removing the last argument of your TweenInfo.new() constructors (the 1). That causes it to wait a second before tweening.

https://developer.roblox.com/en-us/api-reference/datatype/TweenInfo

TweenInfo.new ( number time = 1.0, Enum easingStyle = Enum.EasingStyle.Quad, Enum easingDirection = Enum.EasingDirection.Out, number repeatCount = 0, bool reverses = false, number delayTime = 0 )

number TweenInfo.DelayTime
The amount of time that elapses before tween starts in seconds.

2 Likes

You don’t need to stop moving for the Touched event to register. While a debounce would be helpful here, it’s not necessary.

wW6s92EGx6-min

4 Likes

I’m aware of this ty tho.

characafasefasdfasdfadsfads

Oh crappers, I completely forgot that I added a delay of 1 to the tweeninfo mb - nice catch, thanks a whole bunch :smiley: