Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.