How to fix my party system

I have a apierophobia themed lobby, and im trying to script it. When a player tries to join the party I get a error


Server Script:

game.Players.PlayerAdded:Connect(function(plr)
	local partycode = Instance.new('StringValue', plr)
	partycode.Name = 'PartyCode'
	local inparty = Instance.new('StringValue', plr)
	inparty.Name = 'InPlayersParty'
	local playernumber = Instance.new('StringValue', plr)
	playernumber.Name = 'PlayerNumber'
end)

game.ReplicatedStorage:WaitForChild('Createparty').OnServerEvent:Connect(function(plr)
	if game.ReplicatedStorage.Parties:FindFirstChild(plr.Name) then end
	local newfolder = Instance.new('Folder', game.ReplicatedStorage.Parties)
	newfolder.Name = plr.Name
	local plr1 = Instance.new('StringValue', newfolder)
	plr1.Name = 'PartyOwner'
	plr1.Value = plr.Name
	plr.	PlayerNumber.Value = '1'
	--plr.InPlayersParty.Value = plr.Name
end)

game.ReplicatedStorage:WaitForChild('Joinparty').OnServerEvent:Connect(function(plr)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.PartyCode.Value == plr.PlayerGui.MainMenu.Frame.LobbyPage.Box1.InputPassword.TextBox.Text then

			local partyownerfolder = game.ReplicatedStorage.Parties:FindFirstChild(v.Name)

local counter = 0
			for e,f in pairs(partyownerfolder:GetChildren()) do
				counter = counter + 	1
			end
			if counter == 1 then
				local plr2 = Instance.new('StringValue', partyownerfolder)
				plr2.Name = 'Player2'
				plr2.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '2'
			elseif counter == 2 then
				local plr3 = Instance.new('StringValue', partyownerfolder)
				plr3.Name = 'Player3'
				plr3.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '3'
			elseif counter == 3 then
				local plr4= Instance.new('StringValue', partyownerfolder)
				plr4.Name = 'Player4'
				plr4.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '4'
			else
				plr.PlayerGui.MainMenu.Frame.LobbyPage.Box1.InputPassword.TextBox.Text = ''
				plr.PlayerGui.MainMenu.Frame.LobbyPage.Box1.InputPassword.TextBox.PlaceholderText = 'Party is Full!'
			end
		end
	end
end)

Local Script:

local plr = game.Players.LocalPlayer
script.Parent.Create.MouseButton1Click:Connect(function()
--	script.Parent.Box1.Visible = false
	game.ReplicatedStorage.Createparty:FireServer(plr)
	script.Parent.Parent.Parent.BarFrame.Party.PartyName.Text = plr.Name.. "'s Party"
	script.Parent.Parent.Parent.BarFrame.Party.Player1.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	script.Parent.Parent.Parent.BarFrame.Party.Player1.Player1Name.Text = plr.Name
	
end)

script.Parent.InputCodeBox.TextBox.FocusLost:Connect(function()
	if game.ReplicatedStorage.Parties:FindFirstChild(plr.Name) then 
		plr.PartyCode.Value = script.Parent.InputCodeBox.TextBox.Text
	else
		script.Parent.InputCodeBox.TextBox.Text =''
		script.Parent.InputCodeBox.TextBox.PlaceholderText = 'Create A Party First!'
		wait(2)
		script.Parent.InputCodeBox.TextBox.PlaceholderText = ''
		script.Parent.Parent.Parent.BarFrame.Party.RoomCode.Text = plr.PartyCode.Value
	end
end)

script.Parent.Box1.Confirm.MouseButton1Click:Connect(function()
	if script.Parent.Box1.InputPassword.TextBox.Text ~= '' then
		for i,v in pairs(game.Players:GetChildren()) do
			if v.PartyCode.Value == script.Parent.Box1.InputPassword.TextBox.Text then
				game.ReplicatedStorage.Joinparty:FireServer(plr)
				script.Parent.Box1.InputPassword.TextBox.Text = ''
				script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Joining Party'
				
			else
				script.Parent.Box1.InputPassword.TextBox.Text = ''
				script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Party Code Is Incorrect'
			end
		end
	else
		script.Parent.Box1.InputPassword.TextBox.Text = ''
		script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Enter A Party Code!'
	end
end)

while wait(0.1) do
	for i,v in pairs(game.ReplicatedStorage.Parties:GetChildren()) do
		for s, n in pairs(v:GetChildren()) do
			if n ~= '' then
				if n.Value == plr.Name then
				local partyowner = n.Parent
				print(n.Value.. 'is in'.. v.PartyOwner.Value.. "'s party")
				if n.Name == 'Player2' then
					script.Parent.Parent.Parent.BarFrame.Party.Player2.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player2.Player2Name.Text = tostring(n.Value)
				elseif n.Name == 'Player3' then
					script.Parent.Parent.Parent.BarFrame.Party.Player3.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player3.Player3Name.Text = tostring(n.Value)
				elseif n.Name == 'Player4' then
					script.Parent.Parent.Parent.BarFrame.Party.Player4.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player4.Player4Name.Text = tostring(n.Value)
				elseif n.Name == 'PartyOwner' then
					script.Parent.Parent.Parent.BarFrame.Party.Player1.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
						script.Parent.Parent.Parent.BarFrame.Party.Player1.Player1Name.Text = tostring(n.Value)
				end
				end
			end
		end
	end
end

If I am correct, I’m pretty sure the error occurs from this line
local partyownerfolder = game.ReplicatedStorage.Parties:FindFirstChild(v.Name)
I don’t really know how to fix this error, so help is very appreciated.

EDIT: It works only when the same user joins the party.

Looking at your script output, it says Attempt to index nil with GetChildren, so what you are saying isn’t true

It tries to here though. In the pairs.

i think its here, it says server module, assuming that means server script, if the player is sending the event couldnt u just check their party code Individually instead of every single player, you’re also doing the check if the party code is the same in the localscript, and the server which isn’t a good idea

also on another note it may not be a good idea to store your party codes in a value in the player for global joinable servers, id reckon making a table for this and having it insert a custom premade id and checking if the player enters that id and if its the same in the table then join that lobby

Okay, for now I changed the party codes to replicated storage instead, but im still confused on how to get the party owner here

would I check the party code again to get it or something else?

yea so id imagine if u have it in a folder with the players name who is hosting the party with a party code value, or even the name of the folder itself will work, check if the code thats submitted is the same as any of the other codes in the folders, or the folder itself, u can use get descendants for this if you decide to use the 1st route, and have the player who submitted the code join that party 2nd route would be easiest i think

Ive been trying but the same error from the beginning is still there. Here is the new scripts

Server Script:

game.Players.PlayerAdded:Connect(function(plr)
	local partycode = Instance.new('StringValue', game.ReplicatedStorage.PartyCodes)
	partycode.Name = plr.Name
	local inparty = Instance.new('StringValue', plr)
	inparty.Name = 'InPlayersParty'
	local playernumber = Instance.new('StringValue', plr)
	playernumber.Name = 'PlayerNumber'
end)

game.ReplicatedStorage:WaitForChild('Createparty').OnServerEvent:Connect(function(plr)
	if game.ReplicatedStorage.Parties:FindFirstChild(plr.Name) then end
	local newfolder = Instance.new('Folder', game.ReplicatedStorage.Parties)
	newfolder.Name = plr.Name
	local plr1 = Instance.new('StringValue', newfolder)
	plr1.Name = 'PartyOwner'
	plr1.Value = plr.Name
	plr.	PlayerNumber.Value = '1'
	--plr.InPlayersParty.Value = plr.Name
end)

game.ReplicatedStorage:WaitForChild('Joinparty').OnServerEvent:Connect(function(plr, PartyOwner)
	print(PartyOwner)
	local partyownerfolder = nil
	for i,v in pairs(game.Players:GetChildren()) do
		for d,g in pairs(game.ReplicatedStorage.PartyCodes:GetChildren()) do
			if g.Name == tostring(PartyOwner) then
				print('found party w')
			 partyownerfolder = game.ReplicatedStorage.Parties:FindFirstChild(tostring(PartyOwner))
				print('Party Owner is '..tostring(partyownerfolder))
			end
		end
			--local partyownerfolder = game.ReplicatedStorage.Parties:FindFirstChild(v.Name)
			local counter = 0
			for e,f in pairs(partyownerfolder:GetChildren()) do
				counter = counter + 	1
			end	
			if counter == 1 then
				local plr2 = Instance.new('StringValue', partyownerfolder)
				plr2.Name = 'Player2'
				plr2.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '2'
			elseif counter == 2 then
				local plr3 = Instance.new('StringValue', partyownerfolder)
				plr3.Name = 'Player3'
				plr3.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '3'
			elseif counter == 3 then
				local plr4= Instance.new('StringValue', partyownerfolder)
				plr4.Name = 'Player4'
				plr4.Value = plr.Name
				plr.InPlayersParty.Value = v.Name
				plr.	PlayerNumber.Value = '4'
			else
				plr.PlayerGui.MainMenu.Frame.LobbyPage.Box1.InputPassword.TextBox.Text = ''
				plr.PlayerGui.MainMenu.Frame.LobbyPage.Box1.InputPassword.TextBox.PlaceholderText = 'Party is Full!'
			end
	end
end)

Local Script:

local plr = game.Players.LocalPlayer
script.Parent.Create.MouseButton1Click:Connect(function()
--	script.Parent.Box1.Visible = false
	game.ReplicatedStorage.Createparty:FireServer(plr)
	script.Parent.Parent.Parent.BarFrame.Party.PartyName.Text = plr.Name.. "'s Party"
	script.Parent.Parent.Parent.BarFrame.Party.Player1.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	script.Parent.Parent.Parent.BarFrame.Party.Player1.Player1Name.Text = plr.Name
	
end)

script.Parent.InputCodeBox.TextBox.FocusLost:Connect(function()
	if game.ReplicatedStorage.Parties:FindFirstChild(plr.Name) then 
		game.ReplicatedStorage.PartyCodes:FindFirstChild(plr.Name).Value = script.Parent.InputCodeBox.TextBox.Text
	else
		script.Parent.InputCodeBox.TextBox.Text =''
		script.Parent.InputCodeBox.TextBox.PlaceholderText = 'Create A Party First!'
		wait(2)
		script.Parent.InputCodeBox.TextBox.PlaceholderText = ''
		script.Parent.Parent.Parent.BarFrame.Party.RoomCode.Text = 	game.ReplicatedStorage.PartyCodes:FindFirstChild(plr.Name).Value
	end
end)

script.Parent.Box1.Confirm.MouseButton1Click:Connect(function()
	if script.Parent.Box1.InputPassword.TextBox.Text ~= '' then
		for i,v in pairs(game.Players:GetChildren()) do
			if 	game.ReplicatedStorage.PartyCodes:FindFirstChild(v.Name).Value == script.Parent.Box1.InputPassword.TextBox.Text then
				game.ReplicatedStorage.Joinparty:FireServer(plr, 	game.ReplicatedStorage.PartyCodes:FindFirstChild(v.Name))
				script.Parent.Box1.InputPassword.TextBox.Text = ''
				script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Joining Party'
				
			else
				script.Parent.Box1.InputPassword.TextBox.Text = ''
				script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Party Code Is Incorrect'
			end
		end
	else
		script.Parent.Box1.InputPassword.TextBox.Text = ''
		script.Parent.Box1.InputPassword.TextBox.PlaceholderText = 'Enter A Party Code!'
	end
end)

while wait(0.1) do
	for i,v in pairs(game.ReplicatedStorage.Parties:GetChildren()) do
		for s, n in pairs(v:GetChildren()) do
			if n ~= '' then
				if n.Value == plr.Name then
				local partyowner = n.Parent
				print(n.Value.. 'is in'.. v.PartyOwner.Value.. "'s party")
				if n.Name == 'Player2' then
					script.Parent.Parent.Parent.BarFrame.Party.Player2.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player2.Player2Name.Text = tostring(n.Value)
				elseif n.Name == 'Player3' then
					script.Parent.Parent.Parent.BarFrame.Party.Player3.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player3.Player3Name.Text = tostring(n.Value)
				elseif n.Name == 'Player4' then
					script.Parent.Parent.Parent.BarFrame.Party.Player4.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
					script.Parent.Parent.Parent.BarFrame.Party.Player4.Player4Name.Text = tostring(n.Value)
				elseif n.Name == 'PartyOwner' then
					script.Parent.Parent.Parent.BarFrame.Party.Player1.Image = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(n.Value).UserId,Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
						script.Parent.Parent.Parent.BarFrame.Party.Player1.Player1Name.Text = tostring(n.Value)
				end
				end
			end
		end
	end
end

i dont think you need this line, you’re not searching for players, you’re searching for the lobby ID

yeah I didnt delete it incase I wanted to keep it. There is no difference if I am correct, I am not using it at all.

well in the server script i mean, sorry

What would I change, sorry i’m not the best at scripting.

believe me i aint either

id delete this line and use the one below it in your server script, other than that id need to like test it myself and try stuff, cuz u kinda have no need to look and index players where its at

Okay, then how would I fix this?

I’ve tried multiple ways but they all return with nil

oh i see, i think you’re trying to find the player name that is trying to enter the code, and their lobby by the player you’re trying to search for, and their name