Help fixing party system

i’ve ran into some issues in this party system and i’m also gonna provide video so you can understand it.

  1. when a player resets it makes him leave party on the local gui but in server gui his name is still there and the party will still be existant

  2. when a party member leaves the game his name wont be removed from the current party and also cant kick him from the party

robloxapp-20230628-1611552.wmv (1.3 MB)
robloxapp-20230628-1610425.wmv (599.2 KB)

code in serverscriptservice


local tps = game:GetService("TeleportService")
local placeId = 13782072218


game.ReplicatedStorage.PartySystemRE.OnServerEvent:Connect(function(player, instruction, value1, value2)
	
	
	if instruction == "kickPlayer" then
		
		if game.ReplicatedStorage.Parties:FindFirstChild(value1) and value2.Parent == game.ReplicatedStorage.Parties[value1].Players then
			if game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == player.Name or value2.Value == player.Name then
				
				if game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == value2.Value then
					
					for i, playerInParty in pairs(game.ReplicatedStorage.Parties[value1].Players:GetChildren()) do
						
						game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[playerInParty.Value], false, value1)
					end
					
					game.ReplicatedStorage.Parties[value1]:Destroy()
					
				else
					
					game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[value2.Value], false, value1)
					
					value2:Destroy()
				end
			end
		end
		
		
	elseif instruction == "createParty" then
		
		local partyName = value1 or player.Name .. "'s Party"		
		partyName = game:GetService("TextService"):FilterStringAsync(partyName, player.UserId)
		partyName = partyName:GetNonChatStringForBroadcastAsync()
		
		local newParty = Instance.new("Folder")
		newParty.Name = partyName
		
		local players = Instance.new("Folder", newParty)
		players.Name = "Players"
		
		local partyLeader = Instance.new("StringValue", players)
		partyLeader.Name = "Party Leader"
		partyLeader.Value = player.Name
		
		local limit = Instance.new("IntValue", newParty)
		limit.Name = "PlayerLimit"
		limit.Value = 2
		
		newParty.Parent = game.ReplicatedStorage.Parties
		
		game.ReplicatedStorage.PartySystemRE:FireClient(player, true, partyName)
		
		
	elseif instruction == "joinParty" then
		
		if game.ReplicatedStorage.Parties:FindFirstChild(value1) and #game.ReplicatedStorage.Parties[value1].Players:GetChildren() < game.ReplicatedStorage.Parties[value1].PlayerLimit.Value then
			
			local playerValue = Instance.new("StringValue")
			playerValue.Value = player.Name
			playerValue.Parent = game.ReplicatedStorage.Parties[value1].Players
			
			game.ReplicatedStorage.PartySystemRE:FireClient(player, true, value1)
		end
		
		
	elseif instruction == "startParty" then
		
		if game.ReplicatedStorage.Parties:FindFirstChild(value1) and game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == player.Name then
			
			local playersToTP = {}
			
			for i, playerInParty in pairs(game.ReplicatedStorage.Parties[value1].Players:GetChildren()) do
				
				table.insert(playersToTP, game.Players[playerInParty.Value])
			end
			
			
			local tpOptions = Instance.new("TeleportOptions")
			tpOptions.ShouldReserveServer = true
			
			tps:TeleportAsync(placeId, playersToTP, tpOptions)
		end
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	
	for i, d in pairs(game.ReplicatedStorage.Parties:GetDescendants()) do
		
		if d:IsA("StringValue") and d.Value == player.Name then
			
			if d.Name == "Party Leader" then

				for i, playerInParty in pairs(d.Parent:GetChildren()) do

					game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[playerInParty.Value], false, d.Parent.Parent.Name)
				end
				
				d.Parent.Parent:Destroy()

			else

				game.ReplicatedStorage.PartySystemRE:FireClient(player, false, d.Parent.Parent.Name)

				d.Parent.Parent:Destroy()
			end
		end
	end
end)

You set your GUI to rest on respawn. Go to the GUI instance and change that property to false.

ty, fixed issue number 1 but 2 still not fixed

I didn’t read the code but the reason why you can’t remove the player from the party is because the user is nil. You probably save a reference of that player instance that no longer exists. To fix this, use a player-removing event to update the parties. If the user that left is found in any open queue, remove them. You can do this by exposing a method in the module that iterates through all of the parties. You can also use a dictionary to hash the player user id and set that to a specific party key and then you can update the party that way as well.

this is how the player-removing is in the code:


game.Players.PlayerRemoving:Connect(function(player)
	
	for i, d in pairs(game.ReplicatedStorage.Parties:GetDescendants()) do
		
		if d:IsA("StringValue") and d.Value == player.Name then
			
			if d.Name == "Party Leader" then

				for i, playerInParty in pairs(d.Parent:GetChildren()) do

					game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[playerInParty.Value], false, d.Parent.Parent.Name)
				end
				
				d.Parent.Parent:Destroy()

			else

				game.ReplicatedStorage.PartySystemRE:FireClient(player, false, d.Parent.Parent.Name)

				d.Parent.Parent:Destroy()
			end
		end
	end
end)
1 Like

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