Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help? I want to keep this gui up for a few seconds..

Asked by 6 years ago

So, I have this GUI connected to a remoteevent that tells it when to change text and pop up But it's super glitchy, and I'm not sure how to do what I'm trying to do. I want it to stay up if it continues to receive events, but to close if it stops. This might be a bad explanation but I'll try to give an example.

GUI receives notification request from event (gui pops up with number) Whilst gui is still up, receives a notification event again (gui number changes instead of it going down after (blabla) seconds* Waits around 1-2 seconds (gui goes down) Around another 1-2 seconds, another notification request (gui pops up w/ number)

and so forth.

This is the code:

game.ReplicatedStorage.sendnotif.OnClientEvent:connect(function(number)
    local c = script.Parent.n
    c.Parent = script.Parent
    c.number.Text = "+"..number
    c:TweenPosition(UDim2.new(0.438,0,0.85,0), "Out", "Quad", 0.3)
    wait(.85)
    c:TweenPosition(UDim2.new(0.438,0,1.2,0), "Out", "Quad", 0.3)   
end)

1 answer

Log in to vote
0
Answered by 6 years ago

You have 2 problems:

  1. You don't override the Tweens
  2. You don't skip calling the 2nd Tween if the function is activated again.

Fix:

local call = 0 -- number of times the event has been called
game.ReplicatedStorage.sendnotif.OnClientEvent:Connect(function(number)
    call = call + 1
    local startCall = call
    local c = script.Parent.n
    c.Parent = script.Parent
    c.number.Text = "+"..number
    c:TweenPosition(UDim2.new(0.438,0,0.85,0), "Out", "Quad", 0.3, true)
    wait(.85)
    if call ~= startCall then return end -- this means the function has been activated again, so stop
    c:TweenPosition(UDim2.new(0.438,0,1.2,0), "Out", "Quad", 0.3, true)
end)
Ad

Answer this question