Making a party system

I’m trying to make a party system script, but I’m kind of confused on where to start and what to do. It’s not one of those that you send an invite and the other player has to accept and etc. I want it to be a gui that consist of 4 parties and each party can accept up to 4 players. Anyone can join a party by clicking the join button below, and when the countdown for that party reaches 0 then it teleports everyone inside that party into the game. This is the design for it:
partygui
The way I did it at first was by getting the player that pressed the button and sending their player to a server script by remove event, and putting them in a table. But after that part i’m completely clueless.
Help appreciated, thanks.

3 Likes

I would set up a main script that has a loop which consistently repeats that has a wait() inside of it. I would use a for loop that is the time of the countdown and place a wait(1) at the end of this loop. Inside the loop check if the index is 1 and if it is, go through the table you created earlier the script that controls adding to the table would need to be the same as this one to see how many players are in the table in case you don’t want an empty party to start. From here go through the table and set the CFrame of the humanoid root parts of the players to the party locations.

Example code:

local TableOfPlayers = {} -- Add to table later
local CountdownTime = 60 -- seconds

AddToTableEvent.OnServerEvent:Connect(function(Player)
    table.insert(TableOfPlayers, Player) -- Add player to table
end)

for i= CountdownTime, 0, -1 do
    if i == 1 then -- If countdown is at end
        if #TableOfPlayers >= 1 then -- If there is atleast one player
            for i, PlayerToTeleport in pairs (TableOfPlayers) do -- loop through table of players
                PlayerToTeleport.Character.HumanoidRootPart.CFrame =  -- Put where you want to teleport players here
            end
        end
    end
    wait(1)
end

Hope this helps :grinning:

Is this one of the best ways, I never knew how to do mine so, I made instance.new Folder, that contains all the information in values such as the owner, participants, and what the party is for.

Than I just read and write data on the server.
If this is a horrible way, it would be nice to know before I make a big mistake.

I’m not entirely sure if your way is horrible as I am not experienced enough to know if using folders and instance’s hurts performance or is something that shouldn’t be done. I haven’t even finished my first main project however this is just a method I came up with. Some of those instances may have the possibility to be changed for loops or values stored in a script however I’m not really sure if it has an impact.

Thank you, but this would only be for one table, correct? In my case would I have to make 4 different tables.

Also, for some reason my remote event doesn’t fire.

Yeah I believe you would need 4 tables. You could also use a table within a dictionary. Your remote event may not fire as the loop is before the event meaning the script gets no chance to see the code. You can fix this by putting the loop in a coroutine or by putting the event before the loop. See info about coroutines here. I would also recommend the dev kings video if you need a further explanation on YouTube.