I am trying to create a party system like Rumble Quest However, I am unsure how to start. Would I create a folder containing all the parties in something like ReplicatedStorage or would I store the folder in the player? Also, I am trying to make a invite GUI with a list of all players not in your party; is there a way to do this with :GetPlayers or do I have to use some other method? I have searched through the DevForum, but I was not able to find something to help me.
It all depends on how advanced you want it to be.
It depends on how secure you want it to be.
I’d have a party Gui. I would then have the server send the message of each player in each party. The Gui can then display each party and who is in that party. Then upon clicking Join, it will send a remote event message to the server, The player and the party they wish to join.
I’d have the server then send an event to the party owner, bring up a gui saying “Johnny16 wants to join your party.” and have cancel and accept.
Accept sends a remote event to the server to add the player to the party.
You can use team tables.
Maybe have a Create Party button too. If Create, then the server would create a new party Table for that player.
It’s too much work to write up all the code for you but you can write it all up and work it out as much as you can and then if you have bugs, you can come back and share the code and ask why it’s bugging out.
Thanks for the reply! Two question though: What’s team tables? and Where would I store the table?
By team tables, I believe Steve_Speedy means already having a “list” or “table” (I know, list sounds better) of teams inside a server script, or some module script if you like. When someone creates a new team/party, you insert a new list/table of players into the list/table of teams. It’s really just a coded way to organize the whole team thing.
Alternatively, you can use server storage to create a folder for each team/party that is made. Inside each folder can be a collection of string values that correspond to player IDs for each player on the team.
As you can see, it’s really personal preference. I feel like the folder method is simpler and more intuitive, but the appeal is that the “table” method is much cleaner in the workspace.
Hopefully that cleared up some confusion.
It’s always recommended to use the appropriate methodology , here you would use
Players:GetPlayers()--to return an array of connected Players
For your case , @Steve_Speedy has already mentioned a great way , but here’s how I would do it,
Edit from the future (2021): this system was not tested although it’s fairly alright to give you a basis of what you could do.
I did not change the formatting from 1 year ago.
I wrote a few pieces of code :
Main Server Script in Server Script Service :
[4 Events are utilized in my code ]
local Players = game:GetService("Players")
--// Events
local event = game:GetService("ReplicatedStorage").PlayerEvent
local PartyManager = game:GetService("ReplicatedStorage").PartyManager
local PromptRequest = game:GetService("ReplicatedStorage").PromptRequest
local FinalEvent = game:GetService("ReplicatedStorage").FinalEvent
--// The dictionary template
Parties = {
["player"] = { }
}
Players.PlayerAdded:Connect(function(player)
event:FireAllClients()--just to replicate all players' names as buttons to players
--once a new player is added
end)
PartyManager.OnServerEvent:Connect(function(Player,Target_Player)
-- This second event is to prompt a request to allow players to join the target player
local target
if type(Target_Player) ~= "string" then --just to ensure that what we use is a string
target = tostring(Target_Player)
-- target player is the one the player wants to join (the party of)
else
target = Target_Player
local TotalPlayers = Players:GetPlayers()
for _, loopedPlayer in ipairs(TotalPlayers) do
if TotalPlayers[loopedPlayer] then
print("the player still exists")
PromptRequest:FireClient(Players[target],Player)
end
end
end
FinalEvent.OnServerEvent:Connect(function(OnePlayer,wantstojoin)
if Parties[OnePlayer] then--someone is already allowed
table.insert(Parties[OnePlayer] , wantstojoin) Parties[OnePlayer] = { Parties[OnePlayer],wantstojoin }--add the new person with the old one,
--the player who wanted to join was added to the dictionary, with Parties being the dictionary , player name being the key and the people allowed being the values / an array associated with the key
-- to remove all allowed players from one person's key you would do
-- Parties[OnePlayer] = nil
end
end)
end)
Local script one handling OnClient Event functions placed in StarterPlayerScripts :
local Players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerEvent")
local PartyManager = game:GetService("ReplicatedStorage"):WaitForChild("PartyManager")
fixedPosition = UDim2.new(0.356, 0,0.233, 0)--this is where I want it,for now
event.OnClientEvent:Connect(function()
local button = Instance.new("TextButton")
print("called")
for _, player in ipairs(Players:GetPlayers()) do
button.Parent = script.Parent.Frame
button.Position = fixedPosition --you will have to adjust a UI list layout or something
--so that buttons don't overlap, i'm just keeping it random
button.Name = Players.Name
button.Text = tostring(player.Name)
print("done")
end
end)
for _,button in ipairs(script.Parent.Frame:GetChildren()) do
button.MouseButton1Click:Connect(function()
PartyManager:FireServer(button.Text)
end)
end
Second local script in StarterPlayerScripts :
local Players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PromptRequest")
local player = Players.LocalPlayer
local FinalEvent = game:GetService("ReplicatedStorage"):WaitForChild("FinalEvent")
event.OnClientEvent:Connect(function(wantstojoin)
local Gui = player:WaitForChild("PlayerGui")
local AllowToJoinFrame = Gui.AllowPartyFrame
local button = AllowToJoinFrame.AllowToJoinButton
print(tostring(wantstojoin).."wants to join your party")
button.MouseButton1Click:Connect(function()
FinalEvent:FireServer(wantstojoin)
end)
end)
For this should I do some thing like:
Parties {
player1 = {player2, player3}
player2={player1, player3}
player3 = {player2, player1}
}
or do you mean something else?
edited my code (in my post), the way I wrote it you could add stuff like :
FinalEvent.OnServerEvent:Connect(function(OnePlayer,wantstojoin)
local playerName = tostring(OnePlayer.Name)
if table.find(Parties[playerName], tostring(wantstojoin)) then--already in the party table, return
return
end
if Parties[playerName] then --if previous player exists then add the new one
table.insert(Parties[playerName], tostring(wantsToJoin));
end
In the previous code make sure when wantstojoin parameter is passed it’s the name, not the player you might have to edit a little
Thanks! Also, could you show me an example of how a table could possibly look like?
Also, I want the parties to be accessible by any script. Would I have to copy the server script into a module script?
I can also just fire a RemoteFunction from another script to check if a value is in the parties table, right?
What I’m trying to say is that how would I see if player 2 is in player1’s party when they (for example) touch a part?
Also, how would I remove a player from someone’s party? Would I have to loop through every single party?
To completely remove all player’s allowed in a party, just remove all values associated with the key (player’s name) by :
Parties[playerName] = nil--removes all values
or you could remove specific values like for instance :
Parties = {
["player"] = { "PlayerYouWantToRemove", "randomNoob350" , "str"}
}
-- you can define the player or tostring him or something
if Parties["player"] then
if table.find(Parties["player"],"str") then
print("found")
table.remove(Parties["player"],Parties["player"]["str"])
print("removed")
end
end
print(table.unpack(Parties["player"]))--> prints everything other than "str"
as you can see, a specific value ( “str” here) was removed while the previous values remained associated.
You would know when another player is in a party by using table.find
like :
if table.find(Parties[player1],"player2") then
print ("player2 is in player 1's party")