ID:1939074
 
(See the best response by FKI.)
Code:
mob
Login()
usr.Freeze=1
if(src.client.gender=="male")
icon = 'Base.dmi'
density=1
usr.dir=NORTH
icon_state = "Male"
layer=MOB_LAYER+3
usr.ownone = 0
src.loc = locate(94,7,1) //when a player logs in, make their icon's state
usr.Freeze=0
new/obj/HudHealth/Health(usr.client)
new/obj/HudMana/Mana(usr.client)
usr.updateHealth()
usr.updateMana()
return


Problem description: I am trying to have the health bar become invisible until you are teleported to a specific place and then become invisible once you teleport somewhere else. How does that work? it can only be there when you start.

Change the health bar's visibility var to 101 to make it invisible, lower it again to make it visible again when it's ready.
wait what do you mean by 101. Also, just make a var called visibility right?
"invisibility" is a built in var of BYOND, it does what you'd think: DM reference link.
Alright so where would I put it to not be visible. Right under new/obj? Lastly how would I make it visible at the right time
new/obj should be fine.

To make it visible, simply set the object's invisibility back down to 0.

That can probably be done under the code that teleports the mob.
so I would put the new/obj/etc where the person teleports aswell? Then just have invisibily thing again? Sorry I am really confused
mob/verb/Delete_HUD()
usr << "Huds Deleted" // just to let you know it works.
for(var/obj/HudHealth/Health/Health_Stat in client.screen) // deletes only to the object of its specification.
del Health_Stat
..()

for(var/obj/HudMana/Mana/Mana_Stat in client.screen)
del Mana_Stat
..()

mob/verb/Create_HUD()
client.screen += new/obj/HudHealth/Health // creates the new screen object.
client.screen += new/obj/HudMana/Mana
usr.updateHealth() ; usr.updateMana() // calls updates.
Like PJB said, invisibility is the most efficient way of performing this.

Similarly, refer to client.images.
@Hebrons

Weird, every time it's called I get this on the chat box "runtime error: Cannot read null.screen
proc name: New (/obj/HudHealth/Health/New)
usr: Dayvon (/mob/characters)
src: Health (/obj/HudHealth/Health)
call stack:
Health (/obj/HudHealth/Health): New(null)
Dayvon (/mob/characters): Create HUD()
Dayvon (/mob/characters): Link Start()
runtime error: Cannot read null.screen
proc name: New (/obj/HudMana/Mana/New)
usr: Dayvon (/mob/characters)
src: Mana (/obj/HudMana/Mana)
call stack:
Mana (/obj/HudMana/Mana): New(null)
Dayvon (/mob/characters): Create HUD()
Dayvon (/mob/characters): Teleport()"

Lastly the Bars do not get deleted. But it says it does.
Should just do client.screen-= instead of deleting and loop through src.client.screen if ur going with Hebrons' method
What about the error for when it pops up?
look at the code i posted again i edited it , that should fix your problem.
wot
? i tested it it'll work now.
I tried the updated one and they did not work at all, the same problems
The only thing I can think of is similar to when you're in a safe zone and it changes a var to 1 or whatever you define it as.
And you could also set it to certain Z planes
PJB and Konlet gave you sound advice. That code snippet Hebrons gave you is an example of what you shouldn't do if it can be avoided, especially in this case.

Your problem is rather simple and could be handled using a few procs for organization.

First, handling of creating and deleting (should you ever have to) HUD items:

client
// a list holding our created HUD items.
// alternatively, this could be an associative list for better tracking of each
// individual object. It's up to whatever you deem necessary though.
var list/huds

proc/create_HUD(show = 1)
huds = list(
new/obj/HUD/bar/health,
new/obj/HUD/bar/mana,
)

if(show) show_HUD()

proc/delete_HUD()
if(huds)
hide_HUD()
huds = null


Next, the ability to show and hide the HUD on command:

    proc/show_HUD()
if(huds)
screen.Add(huds)

proc/hide_HUD()
if(huds)
screen.Remove(huds)


And voila.

This example isn't meant to be directly integrated into your own code, it's meant to demonstrate one way you could go about your solution. If you attempt you copy and paste it as is, it will not work.
Well I got it to show up and go perfectly, but when it does show up I get this in the Chat Box.

"runtime error: Cannot read null.screen
proc name: New (/obj/HudHealth/Health/New)
usr: Dayvon (/mob/characters)
src: Health (/obj/HudHealth/Health)
call stack:
Health (/obj/HudHealth/Health): New(null)
Dayvon (/mob/characters): Create HUD()
Dayvon (/mob/characters): Show()
runtime error: Cannot read null.screen
proc name: New (/obj/HudMana/Mana/New)
usr: Dayvon (/mob/characters)
src: Mana (/obj/HudMana/Mana)
call stack:
Mana (/obj/HudMana/Mana): New(null)
Dayvon (/mob/characters): Create HUD()
Dayvon (/mob/characters): Show()"


This is the Create Proc I am using.

mob/proc/Create_HUD()
client.screen += new/obj/HudHealth/Health // creates the new screen object.
client.screen += new/obj/HudMana/Mana
src.updateHealth() ; src.updateMana() // calls updates.
Page: 1 2