Need help resolving this AFK system

1. Objective

The primary objective is to ensure that the AFK/queue system functions seamlessly, allowing players to be added or removed from the queue as necessary for the proper operation of the game.

2. Issue Description

The AFK/queue system in our game is currently experiencing disruptions that lead to game-breaking situations. Specifically, when a round ends or a player goes AFK, the system encounters errors. (however, errors don’t show up in the output) It’s important to note that the error appears to be related to the provided script, as the system functions correctly without its inclusion. Notably, the function RWMG.PlayerCheck() is pivotal for initiating the game.

3. Evidence

Unfortunately, I encountered difficulties when attempting to upload a 23-second MP4 video demonstrating the issue. While I’m unable to provide the video at this time, I’ve attached a screenshot that showcases the error.

4. Troubleshooting Steps Taken

Over the course of nearly two days, I have actively worked to address this issue with the assistance of ChatGPT. Although some progress has been made, a solution has not yet been identified. In addition to utilizing ChatGPT, I have scoured both the Roblox Developer Hub and various online forums in an attempt to resolve this issue, but unfortunately, no viable solution has been found thus far.

5. Code Snippet

Here is the relevant code snippet where the issue seems to originate:

function RWMG.MakeQueue()
    for _, player in pairs(Playerr:GetPlayers()) do -- playerr represents the player variable 
        local playerName = player.Name
        local playerGui = player:FindFirstChild("PlayerGui")
        local isAFK = playerGui and playerGui:FindFirstChild("AFK") and playerGui.AFK.AFKValue

        if isAFK.Value == false then
            table.insert(InGameTable, playerName)
            print(playerName .. " is not AFK")
        else
            table.remove(InGameTable, playerName)
            print(playerName .. " has gone AFK")
        end
    end

    repeat wait() until #InGameTable >= 2
    if #InGameTable >= 2 then
        RWMG.PlayerCheck(InGameTable) -- start game
    else
        print("not ready")
    end
end

6. Request for Assistance

Given the critical nature of the AFK/queue system to our game’s functionality, I am seeking the expertise of the Roblox community to help identify and rectify the underlying issue. Any guidance, insights, or solutions that can be provided to resolve this problem would be greatly appreciated.

Thank you for your support!

2 Likes

The usage of “table.remove(InGameTable, playerName)” seems to be what’s tripping you up. The second argument of ‘table.remove’ should be an index. As a result, you’ll need to find the user’s index value in the table.

Additionally, I’d recommend inserting some Pcall functions in your code.

function FindPlayerIndex(targetName)
	for Index, Username in ipairs(InGameTable) do
		if Username == targetName then
			return Index
		end
	end
	
	return nil
end
1 Like

Never used Pcalls before, i’ll see what i can do to implement it in though. do they work in module scripts by any chance? Thank you!

1 Like

Indeed, they do.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.