You can write your topic however you want, but you need to answer these questions:okay
-
What do you want to achieve? I want to make a OOP Party System
-
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…
- 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!