OnServerInvoke very delayed?

Hello, I have a strange issue with OnServerInvoke(). I am making a team system, where I want to make sure each team at least has 1 player, and a balancing system I will code in the future. However, the scripts are very delayed, not by a second, but a whole 1-2 minutes. I do not know what the cause is, as I’ve tried a local server, and in studio, however both produce the same result. There is no wait() or anything of the similar anywhere in the scripts, so that is why I am confused. Any help is appreciated, thank you :slight_smile:

local central, enter = game.Teams["Central Powers"], game.Teams["Entente Powers"]

local teamTable = {
    [1] = enter,
    [2] = central

local function checkIfTeam(player, num)
    local team = teamTable[num]

    if #central:GetPlayers() >= 1 and #enter:GetPlayers() == 0 then
        if team == central then 
            return false 
            player.Team = enter
            return true
    elseif #enter:GetPlayers() >= 1 and #central:GetPlayers() == 0 then
        if team == enter then 
            return false
            player.Team = enter
            return true
    player.Team = team

canJoin.OnServerInvoke = checkIfTeam
for _, v in ipairs(script.Parent:GetChildren()) do 
    if v:IsA("ImageButton") then
            print("hi :)") 
            --if timerEnabled == true then
            print("hru :D")
            local join = canJoin:InvokeServer(tonumber(v.Name))


            if join == false then
                local tween = game:GetService("TweenService"):Create(script.Parent.Warning, TweenInfo.new(), {TextTransparency = 0})


This is most likely an engine bug. I would wait, and possibly contact Roblox Support, because there’s nothing wrong with the server invoke.

It might be, I asked a couple other people, and they think its an issue that has to do with how the modules and timers work. Ive put all these scripts in its own seperate scripts./modules, however nothjing has changed, so I do believe its an engine bug. Thanks for letting me know,

Yeah this has been a thing for a while now sadly.
As @ItsKoolPlayz said, your best bet is to contact support and go from there.

You may have some code which is causing the main thread to yield for long periods of time (busy waits).