ID:2184234
 
(See the best response by Ter13.)
Code:
        PUpdate()//called by the current leader everytime someone leaves,enters the party,or is changed to leader status 
if(!lead) return
for(var/mob/M in party)
if(M!=src)
if(M.party.len)
M.party.Remove(M.party)
M.party.Add(party)
for(var/mob/M in party)
M.PartyMeters()



PartyMeters()
if(inparty)
for(var/obj/HUD/PMeters/o in client.screen)
del o
var/hudstart=12//location on the y-axis where the HUD will be added
for(var/i=1;i<=party.len;i++)
for(var/mob/M in party)
if(M.partyid==i && M!=src)
new/obj/HUD/PMeters/BG(client,hudstart,M)
new/obj/HUD/PMeters/PHP(client,hudstart,M)
new/obj/HUD/PMeters/PE(client,hudstart,M)
Partytext(M.name,hudstart)
updatePStats()
hudstart--


Problem description:
I recently started implementing a party system in my code, and began to set up a feature where people in your party can monitor your basic statistics(HP and Energy). Even though I've currently only tested it with two people only the member who isn't the party leader gets the hp bars. When I use a coded verb to switch the leader roles the previous leader then receives the HUD additions that he hadn't received earlier, but everyone in the party is supposed to receive the extra HUD elements whenever the party contents are collectively updated.
Best response
http://www.byond.com/forum/?post=1810538

http://www.byond.com/forum/?post=2017162#comment18065405

Addendum to second link:

mob
var/tmp
list/party_meters

obj/HUD/PartyMeter

party
Join(mob/m)
..()
m.party_meters = list()
var/obj/HUD/PartyMeter/p
for(var/mob/n in members)
p = new/obj/HUD/PartyMeter(m.client,n)
p.show()

Leave(mob/m)
..()
for(var/obj/HUD/PartyMeter/p in m.party_meters)
p.hide()
m.party_meters = null


Basically, each party member's bar shouldn't be deleting and recreating itself every frame. Switch to a state based approach and create a system that notifies you when a player leaves or joins. Update the party bars from within their own code, and NEVER search through the screen using a for loop.
In response to Ter13
Thanks for the advice, and especially for the two links posted. I had been reading your snippet sundays, but had lost my bookmarks and couldn't work up the drive to find them again. Also,the member bars are not deleted and recreated with every frame, but instead updated via a proc only when a member of your party takes damage or uses energy and I have already created a system which notifies you when a player leaves or joins. My main intention for PUpdate() is to rearrange the ordering of the member bars (leader always in first). However, it's obvious that you would not know this as I only snipped where I thought the error was, instead of all related code, as I did not want to discourage any potential helpers with text walls...like this