OOP Party System Issue

You can write your topic however you want, but you need to answer these questions:okay

  1. What do you want to achieve? I want to make a OOP Party System

  2. What is the issue? I’m not sure exactly, but I’ll explain it first.

There may be some weird parts because I’m using a translator. sorry!

I used this module to make a party system, and I wrote a server script that basically make a party for that player when player join lobby server. but every time i test, I printed the party list and I could see the last participating player’s party appeared to overwrite all the parties.

This is the beginning part of the script, just in case it helps you solve the problem.↓

local Party = {}
Party.__index = Party

local Players = game:GetService("Players")

local Parties = {};
local PhysicalParty
local defaultMaxMembers = 5
local inviteCooldown = 20

and I just replaced “Party” to “newparty”
(there were no edits in the code other than this)

--// Party object function --\\

-->> Create a new party
function Party.new(Leader: Player)
	if Parties[Leader] then
		warn(("%s is already a party leader!"):format(Leader.Name))
		return Parties[Leader]
	end
	
	local newparty = {}
	setmetatable(newparty, Party)
	newparty.Leader = Leader;
	newparty.MaxMembers = defaultMaxMembers;
	newparty.CurrentMemberCount = 0;
	newparty.InviteOnly = false;
	newparty.Members = {};
	newparty.Invites = {};
	newparty.Blacklist = {};
	
	PhysicalParty = script.Parent.PhysicalParties.PartyTemplate:Clone()
	newparty:addMember(Leader)

	PhysicalParty.Name = Leader.Name
	PhysicalParty.Parent = script.Parent.PhysicalParties
	PhysicalParty.Members[Leader.Name]:SetAttribute("Leader", true)
	PhysicalParty.Members[Leader.Name]:SetAttribute("CanKick", true)
	PhysicalParty.Members[Leader.Name]:SetAttribute("CanInvite", true)

	Parties[Leader] = newparty

	print(Parties)
	return newparty
	
	--[[ and here is the original version↓
	setmetatable({}, Party)

	Party.Leader = Leader;
	Party.MaxMembers = defaultMaxMembers;
	Party.CurrentMemberCount = 0;
	Party.InviteOnly = false;
	Party.Members = {};
	Party.Invites = {};
	Party.Blacklist = {};		

	PhysicalParty = script.Parent.PhysicalParties.PartyTemplate:Clone()
	Party:addMember(Leader)

	PhysicalParty.Name = Leader.Name
	PhysicalParty.Parent = script.Parent.PhysicalParties
	PhysicalParty.Members[Leader.Name]:SetAttribute("Leader", true)
	PhysicalParty.Members[Leader.Name]:SetAttribute("CanKick", true)
	PhysicalParty.Members[Leader.Name]:SetAttribute("CanInvite", true)

	Parties[Leader] = Party

	print(Parties)
	
	return Party
	]]--
end

and

hrer is the invite function script below ↓

-->> Invites a player to the party
function Party:invitePlayer(Player: Player)
	print(self)
	if self.Invites[Player] then
		warn(("%s already has an invite. Wait before sending another."):format(Player.Name))
		return
	end

	if self.Members[Player] then
		warn(("%s is already a party member."):format(Player.Name))
		return
	end

	self.Invites[Player] = self
	createNewInstance("ObjectValue", PhysicalParty.Invites, Player.Name, Player)

	spawn(function()
		task.wait(inviteCooldown)
		self.Invites[Player] = nil

		if PhysicalParty.Invites:FindFirstChild(Player.Name) then
			PhysicalParty.Invites[Player.Name]:Destroy()
		end
	end)
end

(I’m sorry there are so many scriptss) So let’s get to the point and the problem is this error occurs every time the test invites another player to a party.

I have no idea why this error occurs…

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?no…

I’m new to this kind of OOP system and module script, so I’m not sure. anyone can help, that would be great. and If you’re curious about the full script, please refer to this link I attached earlier. Thank you Happy New Year!

1 Like

In your script you return “Party” but the Party is not your new OOP object instead it is the module itself - so you should return newparty!
Let me know if this fixed your problem

1 Like

Sorry, I think I wrote the wrong script when I posted it. I’ve edited it.

But the result was the same when returned newparty or party. Why is this…
The table above the error code in this picture is the result of print(self) in the invitation function of the module script.

1 Like

I just figured it out! I could have known faster if I had posted the full code… I’ll have to show the full code next post. Sorry,

local function handleRemoteRequest(Player, Request, Data)
	if Request == "InvitePlayer" then
		if getPlayerParty(Player) and getPlayerParty(Player):GetAttribute("CanInvite") == true then
			Party:getParty(Player):invitePlayer(Data.InvitedPlayer)--edited This Line
			--Party:invitePlayer(Data.InvitedPlayer) Original Line
		end
	elseif Request == "AcceptInvite" then
		if playerHasInvite(Player) then
			playerHasInvite(Player):addMember(Player)
			removePlayerInvites(Player)
		end
	end
end

PartyRemote.OnServerEvent:Connect(handleRemoteRequest)

return Party

This was the code to use remote events to receive invitation requests from clients and execute invitation functions.
I don’t know why the original creator did that, but he was using the invite function in the party module script itself. So I modified it, and now I see the nickname of the invitee as normal.
Anyway, thank you so much for your help!

Hi, original creator here :slight_smile: I appreciate your interest in my system and am happy to assist with any further issues you may run into. Feel free to contact me directly through the ROBLOX site and i’d be happy to help

1 Like

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