How to handle things that happen at the EXACT same time through RemoteEvents?

This is mostly with handling data from remote events, but an example is a killfeed.
How should I handle data that is sent at the exact same time? This happens like if I use a :kill command from an admin commands script on 2 people at the same time. Anyone have any idea how I could properly handle receiving data at the same time so I could schedule it and make it happen separately? The only way this could occur is if the function is being called at the exact same time. The text for a kill feed just gets combined.

what it looks like:
https://gyazo.com/65ef1687d69c58a5953dd4631e03995a

local add_killfeed_entry=function(…) --do stuff end
remote_event.OnClientEvent:Connect(function(…)
add_killfeed_entry(…)
end)

2 Likes

Asserting Solution


Queuing system using RunService.Heartbeat(or any refreshing time appropriate for it). You add up the queue of killfeed to an array. The array will be used to display one killfeed at a RunService.Heartbeat. When one is displayed, remove it from the array.

This is what I could think of so far.

Oh, and if it’s not clear enough. Use the array’s first index through the queue.

1 Like

What I do for Killfeeds is simply have a UIListLayout inside of the container or Frame you will be displaying kills in. Then either have a premade template entry that you can just clone and parent, or make an entry manually. When the event connects, change the text in the entry and parent it to the container. The UIListLayout will ensure that when you parent them they stack on top/below of each other and you won’t have an override. After a few seconds delete them (you can use delay for this when the event connects, to schedule the entry’s destruction for later).

1 Like

I will make sure to try the idea by queuing. However, if I use the UIListLayout, I won’t be able to really animate it in. I was doing it without so I could fade in the new killfeed entries and tween them in, and tween the others up. I think I could maybe do some animating stuff with the UIListLayout by having frames on the edges to resize to make it seem like it’s being tweened in, and the text fade will work either way. I’ll try the queuing idea first, then the UIListLayout if it doesn’t work. Thanks!

I use the exact method I listed above and it tweens just fine to achieve the effect you described. Parenting an entry to the frame will tween the others up, it won’t just snap in. Also you can make the text invisible and once parented just tween the transparency in, and back out before you destroy it. Up to you what way you want to do it.

How do you get them to tween in? Every time I’ve used a UIListLayout, it snaps objects in. It doesn’t tween them upward.

It’s pretty simple to make things happen one after the other. Here’s an example module you can use:

local Queue = {}
Queue._mt = {__index = Queue}

-- create a new Queue object, which can be used to run things one after the other.
function Queue.new()
    local self = setmetatable({}, Queue._mt)
    self.pendingTasks = {}
    self.running = false
    return self
end

-- queue a function to run later
-- if no other functions are currently queued, this will run immediately
-- if other functions are queued, this will run after all other functions have completed execution
function Queue:QueueTask(callbackFunc)
    table.insert(self.pendingTasks, callbackFunc)
    if not self.running then
        self:Run()
    end
end

-- internally called to start processing all pending tasks
function Queue:Run()
    self.running = true
    spawn(function()
        while #self.pendingTasks > 0 do
            local task = table.remove(self.pendingTasks, 1)
            task()
        end
        self.running = false
    end)
end

return Queue

(wrote that just now so forgive me if there’s any errors :slightly_smiling_face:)

To use that module, just call Queue.new to create a new queue. Every queue object keeps its own internal list of pending tasks, so you can use multiple queue objects at the same time if you like. To queue a function to run, you can call :QueueTask(func) on your queue object (func = the function to run).

Here’s a working example:

local function foo()
    print("Waiting for 2 seconds...")
    wait(2)
end

local function bar()
    print("mayo")
end

local q = Queue.new()
q:QueueTask(bar)
q:QueueTask(foo)
q:QueueTask(bar)

In the output, you should see mayo and Waiting for 2 seconds..., and then after 2 seconds you’ll see another mayo.

So when you recieve your remote events, you can just :QueueTask() straight away. Then, the functions will be forced to run one after the other, even if you get two events at the same time.

Hope this helps!

7 Likes

Set the Vertical alignment to Top and when you parent them in to the bottom, it’ll push everything up.

The alignment properties I have down, but I don’t understand where the tweening is coming from. Regardless of what properties I set on the layout object, it snaps, it doesn’t tween.

Do you have a screenshot or something to work off of, or am I misunderstanding your implementation?

Generally the way I would handle this feed animation would be listening for any new addition and resizing the container frame when adding a new member. Here’s a sample psudocode:

  1. Events are fired for the feed.
  2. We add the new notification in, listing it at the bottom of the frame (UIListLayout or programatically).
  3. We resize the container by the height of the new addition, keeping everything “In Place” as we added new elements to the bottom.
  4. We tween or programatically move the container up so the new notification slides into view. We can also add a fade-in to make it super pretty.
  5. We remove (can fade out first) the notification after some time, when we delete it, we resize the container down 1 height again, and move it’s position down 1 height as well so that we keep everything in place.
1 Like

My question specifically pertains to the presence of a tween in a UIListLayout. I’m not sure how LordHammy is achieving a UIListLayout tween, since my experience with it is that it snaps children based on the properties of the layout object to certain positions.

In terms of creating a feed though, UIListLayout specifics aside, I agree, this is essentially the same thing I would do.

1 Like

The container should be tweened, which will tween the entire list as they are all positioned relative to their parent frame.

“We tween or programatically move the container”

This is in reference to a frame that you would have all of the “notifications” inside of.

1 Like

Correction from the last post, if you set the Vertical Alignment to bottom, it should work. “Tween” is probably the wrong word but it certainly is a transition effect. If you parent a button to a frame containing a UIListLayout with the Vertical Alignment on Bottom it will almost push the previous instance up and take it’s place.

Sorry for bumping, but how do I pass arguments with the function please? Thanks for reading this!