Need Help with Party System

Hello! This is my first time trying to do this system. I was modifying HowToRoblox’s Party System. I modify it to be able to choose Arc —> chapter(1-10) and it work! but the problem start to arrive.

Problem Line 90 - 94: I’m not sure why currentSelectChapter and currentListChap keep returning nil result in “No Chapter Selected” if someone can point out what did I do wrong, please.

image


image

Fullscript:

print("Script_Version_1.0.0")


local open = script.Parent:WaitForChild("Open")
local main = script.Parent:WaitForChild("Main"); main.Visible = false
local close = main:WaitForChild("Close")

local rs = game.ReplicatedStorage:WaitForChild("PartyRS")
local re = rs:WaitForChild("RE")
local parties = rs:WaitForChild("Parties")

local inParty = nil

local lastSelectedChapter = nil
local currentSelectChapter = nil
local currentListChap = nil



local activeFuncs = {}

function runOnce(func, name)
	if activeFuncs[name] then
		task.cancel(activeFuncs[name])
		activeFuncs[name] = nil
	end
	func()
end

function formatSeconds(totalSecs)

	local mins = tostring(math.floor(totalSecs / 60))
	local secs = tostring(totalSecs - (mins * 60))

	if string.len(mins) < 2 then
		mins = "0" .. mins
	end
	if string.len(secs) < 2 then
		secs = "0" .. secs
	end

	local formatted = mins .. ":" .. secs
	return formatted
end

function displayPage(requestedPage)
	for i, page in pairs(main:GetChildren()) do

		if page:IsA("Frame") then
			if page.Name == requestedPage.Name then
				page.Visible = true
			else
				page.Visible = false
			end
		end
	end
end

function getAvatar(playerName)
	if game.Players:FindFirstChild(playerName) then
		local uid = game.Players[playerName].UserId

		local image = game.Players:GetUserThumbnailAsync(uid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
		return image
	end
end

function displayParties()
	for i, partyFrame in pairs(main.PartiesPage.PartiesList:GetChildren()) do
		if partyFrame:IsA("Frame") then
			partyFrame:Destroy()
		end
	end

	local partyFrames = {}

	for i, party in pairs(parties:GetChildren()) do
		local partyFrame = script.PartyPageParty:Clone()
		table.insert(partyFrames, partyFrame)
        
		local c1, c2 = nil

		local function updatePartyFrame()	
			if not partyFrame then
				c1:Disconnect()
				c2:Disconnect()
				return
			end
			
			if currentSelectChapter and currentListChap then
				partyFrame.ChapterLabel.Text = currentSelectChapter.Name .. ":" .. currentListChap.Name
			else
				partyFrame.ChapterLabel.Text = "No Chapter Selected"
			end

			partyFrame.NameLabel.Text = party.Name

			local leader = nil
			local members = {}

			for x, member in pairs(party.Members:GetChildren()) do
				if member:FindFirstChild("Leader") then
					leader = member.Name
				else
					table.insert(members, member.Name)
				end
			end

			partyFrame.Leader.Image = getAvatar(leader)

			table.sort(members, function(a, b)
				return a < b
			end)
			for x, member in pairs(members) do
				local memberImage = script.PartyPageMember:Clone()
				memberImage.Image = getAvatar(member)

				memberImage.Parent = partyFrame.MembersList
			end
			
			
			local numberOfMembersLabel = partyFrame:FindFirstChild("NumberOfMembers")
			
			if numberOfMembersLabel then

			partyFrame.NumberOfMembers.Text = #party.Members:GetChildren() .. "/" .. party.MaximumMembers.Value
			
			else
				warn("NumberOfMembers not found in partyFrame")
			end

		end
		c1 = party:WaitForChild("Members").ChildAdded:Connect(function()
			runOnce(updatePartyFrame, "updatePartyFrameDisplay")
		end)
		c2 = party:WaitForChild("Members").ChildRemoved:Connect(function()
			runOnce(updatePartyFrame, "updatePartyFrameDisplay")
		end)
		runOnce(updatePartyFrame, "updatePartyFrameDisplay")

		partyFrame.Join.MouseButton1Click:Connect(function()
			re:FireServer("JOIN", party.Name)
		end)
	end

	table.sort(partyFrames, function(a, b)
		return a.NameLabel.Text < b.NameLabel.Text
	end)
	for i, partyFrame in pairs(partyFrames) do
		partyFrame.Parent = main.PartiesPage.PartiesList
	end

	displayPage(main.PartiesPage)
end

function displayInParty(party)
	local partyFolder = typeof(party) == "string" and parties[party] or party

	local c1, c2 = nil

	local function updatePartyFrame()

		if inParty ~= party then
			c1:Disconnect()
			c2:Disconnect()
			return
		end

		for i, memberFrame in pairs(main.InPartyPage.MembersList:GetChildren()) do
			if memberFrame:IsA("Frame") then
				memberFrame:Destroy()
			end
		end

		main.InPartyPage.NameLabel.Text = partyFolder.Name

		local leader = nil
		local members = {}

		for i, member in pairs(partyFolder.Members:GetChildren()) do
			if member:FindFirstChild("Leader") then
				leader = member.Name
			else
				table.insert(members, member.Name)
			end
		end
		table.sort(members, function(a, b)
			return a < b
		end)

		local leaderFrame = script.InPartyPageMember:Clone()
		leaderFrame.NameLabel.Text = leader
		leaderFrame.Avatar.Image = getAvatar(leader)
		leaderFrame.Kick.Visible = false

		leaderFrame.Parent = main.InPartyPage.MembersList

		if leader == game.Players.LocalPlayer.Name then
			leaderFrame.BackgroundColor3 = Color3.fromRGB(244, 236, 193)
			main.InPartyPage.Queue.BackgroundColor3 = Color3.fromRGB(67, 168, 87)
		else
			main.InPartyPage.Queue.BackgroundColor3 = Color3.fromRGB(172, 167, 165)
		end

		for i, member in pairs(members) do
			local memberFrame = script.InPartyPageMember:Clone()

			memberFrame.NameLabel.Text = member
			memberFrame.Avatar.Image = getAvatar(member)
			memberFrame.Leader.Visible = false

			if member == game.Players.LocalPlayer.Name then
				memberFrame.BackgroundColor3 = Color3.fromRGB(244, 236, 193)
			end

			if leader == game.Players.LocalPlayer.Name then
				memberFrame.Kick.Visible = true

				memberFrame.Kick.MouseButton1Click:Connect(function()
					re:FireServer("KICK", member)
				end)
			end

			memberFrame.Parent = main.InPartyPage.MembersList
		end
	end

	c1 = party.Members.ChildAdded:Connect(function()
		runOnce(updatePartyFrame, "updatePartyFrameIn")
	end)
	c2 = party.Members.ChildRemoved:Connect(function()
		runOnce(updatePartyFrame, "updatePartyFrameIn")
	end)
	runOnce(updatePartyFrame, "updatePartyFrameIn")

	displayPage(main.InPartyPage)

	while inParty == party do
		if party:FindFirstChild("IN QUEUE") then
			main.InPartyPage.Queue.Text = formatSeconds(party["IN QUEUE"].Value)
		else
			main.InPartyPage.Queue.Text = "Queue"
		end
		task.wait(0.2)
	end
end




function displayCreateParty()
	displayPage(main.CreatePage)
end


function displayChapter(RequireChap)
	lastSelectedChapter = RequireChap.Name  

	displayPage(main.Chapter)
	main.Chapter.Title.Text = lastSelectedChapter

	currentSelectChapter = RequireChap

	for i, chapterButton in pairs(main.Chapter:GetChildren()) do
		if chapterButton:IsA("TextButton") then
			chapterButton.MouseButton1Click:Connect(function()
				runOnce(function() 
					displayListChap(chapterButton) 
				end, "displayListChap")
			end)
		end
	end
end

function displayListChap(RequireChap)
	displayPage(main.ListChap)
	main.ListChap.Title.Text = RequireChap.Name

	currentListChap = RequireChap
end



open.MouseButton1Click:Connect(function()

	if main.Visible == false then
		main.Visible = true

		if inParty then
			displayInParty(inParty)
		else
			displayParties()
		end

	else
		main.Visible = false
	end
end)
close.MouseButton1Click:Connect(function()
	main.Visible = false
end)





main.PartiesPage.Create.MouseButton1Click:Connect(function()
	runOnce(displayCreateParty, "displayCreateParty")
end)

main.CreatePage.Back.MouseButton1Click:Connect(function()
	runOnce(displayParties, "displayParties")
end)
parties.ChildAdded:Connect(function()
	if main.PartiesPage.Visible == true then
		runOnce(displayParties, "displayParties")
	end
end)
parties.ChildRemoved:Connect(function()
	if main.PartiesPage.Visible == true then
		runOnce(displayParties, "displayParties")
	end
end)


main.Chapter.Back.MouseButton1Click:Connect(function()
	runOnce(displayParties, "displayParties")
end)

main.ListChap.Back.MouseButton1Click:Connect(function()
	runOnce(function() 
		if lastSelectedChapter then
			displayChapter({ Name = lastSelectedChapter }) 
		end
	end, "displayChapter")
end)


main.CreatePage["The Beginning"].MouseButton1Click:Connect(function()
	runOnce(function() displayChapter(main.CreatePage["The Beginning"]) end, "displayChapter")
end)

main.CreatePage["The Hotel"].MouseButton1Click:Connect(function()
	runOnce(function() displayChapter(main.CreatePage["The Hotel"]) end, "displayChapter")
end)



main.ListChap.Create.MouseButton1Click:Connect(function()
	local MaxMembers = 6
	if MaxMembers then
		print("Selected Chapter: " .. currentSelectChapter.Name)
		print("Selected List: " .. currentListChap.Name)

		re:FireServer("CREATE", MaxMembers, currentSelectChapter, currentListChap)
	end
end)


main.InPartyPage.Leave.MouseButton1Click:Connect(function()
	re:FireServer("LEAVE")
end)

main.InPartyPage.Queue.MouseButton1Click:Connect(function()
	re:FireServer("QUEUE")
end)


re.OnClientEvent:Connect(function(instruction, party)

	if instruction == "JOIN" then
		inParty = party
		displayInParty(party)

	elseif instruction == "LEAVE" then
		inParty = nil
		displayParties()
	end
end)

Thank you for reply!

2 Likes

if this can help you!

1 Like

bro, did you notice that local open and local close are blue colored (that means its a roblox system variable) like local wont work if u put something from roblox. ex: local wait = 1

Rename locals into another name, like close to closeparty and open to openparty

1 Like

that is not the problem… also I don’t know why it is blue in this

1 Like

switch the locals’s names so they turn white and modify the script to correct them to new locals, and try running the script

1 Like

are you sure that we are talking about ChapterLabel?

1 Like

image

1 Like

more info: It is a nil to other player except owner

1 Like

i may have found the problem: did you make the system which changes the nil to another value?

1 Like

please elaborate that :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question: :question:

1 Like

these part?


function displayChapter(RequireChap)
	lastSelectedChapter = RequireChap.Name  

	displayPage(main.Chapter)
	main.Chapter.Title.Text = lastSelectedChapter

	currentSelectChapter = RequireChap

	for i, chapterButton in pairs(main.Chapter:GetChildren()) do
		if chapterButton:IsA("TextButton") then
			chapterButton.MouseButton1Click:Connect(function()
				runOnce(function() 
					displayListChap(chapterButton) 
				end, "displayListChap")
			end)
		end
	end
end

function displayListChap(RequireChap)
	displayPage(main.ListChap)
	main.ListChap.Title.Text = RequireChap.Name

	currentListChap = RequireChap
end

1 Like

image
If it was these then I need it to send to server to change mapid, but I don’t think these are the cause of problem

1 Like

Only thing i found in your script that is you are making these locals and not changing the set variable then checking if chapter selected

1 Like

oh yeah It might be that. I will change some part real quick

1 Like

so weird

        print("Selected Chapter: " .. currentSelectChapter.Name)
		print("Selected List: " .. currentListChap.Name) 

image
it did print something except nil(both server and client)

1 Like

image
Help me

Rule 1: if it works, dont touch it

so true :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart: :broken_heart:

I finally done it I add new value called Arc and Chapter. IT WORK!

did it make your script better by telling you that you forgot to change values from nil?