Garry's Mod Gamemode Scripting | HUD: Health | Part 3


Garry’s Mod Gamemode Scripting is a series aimed at creating our own gamemode from start to finish. In this episode, we begin work on our custom HUD.

Buy me a coffee:
Support the channel by shopping on Amazon:
Get a free audiobook:

My Gear:
Keyboard –
Microphone –
Pop Filter –
Mic Stand –

Thanks for watching and I hope you enjoyed!

  1. Whut McCrimmon says

    I followed all the correct steps presented in the video and learned a new piece of code each step. Everything turned out correct. Thanks for the awesome video. Keep it up!

  2. Andezit says

    It doesn't work, because there isn't "TestHud" in hook.lua 84

  3. Rocha xDK says

    mine does not disappear and I did not save what I do.Couldn't include file 'shared.lua' (File not found) (@gamemodes/gamemode/gamemode/cl_init.lua (line 1))Couldn't include file 'testhud.lua' (File not found) (@gamemodes/gamemode/gamemode/cl_init.lua (line 2))

  4. TheGamingBegins says

    How to do so you change hp in the hud when you change job?

  5. DFault says

    I've checked many times to make sure that my script is proper and for whatever reason I cannot get the default hud to hide. Any tips?

  6. Eean Ditto says

    My hud isn't appearing and I have quadruple checked to make sure I did everything right, I keep getting this error,
    [ERROR] gamemodes/bktrumble/gamemode/testhud.lua:4: attempt to call method 'Alive' (a nil value)
    1. v – gamemodes/bktrumble/gamemode/testhud.lua:4
    2. unknown – lua/includes/modules/hook.lua:84

  7. Mr.Ulysses says

    Hey Mate, i need help :/ function HUD()endhook.Add("HUDPaint", "TestHud", HUD)function HideHud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end end endhook.Add("HUDShouldDraw", "HideDefaultHud", HideHud)

  8. Robert J. Oppenheimer says

    i followed the steps on the hud and checked it twice, I derived it properly (from what I know) and I don't know what could be going wrong.
    function HideHud(name)
    for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do
    if name == v then
    return false
    hook.Add("HUDShouldDraw", "HideDefaultHud", HideHud)

  9. MisterDoctorUnknown says

    Any way to change the font size of the text?

  10. Viking Wolf says

    Hey i've followed what you have done up to where you tested it to see a blank box, however it does not remove the HUD for me and produces no errors. Many thanks for any help you can give!

  11. Neo Florian says

    I'm modifying the sandbox gamemode in my server and I get an error for the 'local client = LocalPlayer()' line that says: "attempt to call global 'LocalPlayer' (a nil value)"Help?

  12. Erica Millican says

    This is what I have and it’s not getting rid of default HUD:function HUD()endhook.Add("HUDPaint", "TestHud", HUD)function HideHud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end endendhook.add("HUDShouldDraw", "HideDefaultHud", HideHud)What is wrong??

  13. ncx says

    hello, can you make a video about making bots for:TTT, SANDBOX and ZOMBIE SURVIVAL gamemodes?

  14. A_Moist_Man says

    Imma tell ya this cuz I love ya, but this:draw.DrawText("Healthn"..client:Health(), "CloseCaption_Bold", 50, ScrH()-100, Color(255, 255, 255, 255), 1)Similar to the draw.DrawSimpleText()- those last two 0's at the end just have to do with text alignment. Like I have a 1 at the end, that just centers the text across the X axis.So in this code:draw.DrawText("Health"..client:Health(), "CloseCaption_Bold", 50, ScrH()-100, Color(255, 255, 255, 255), 0, 0)The , 0, 0) at the end will align your text in the X and Y axis.Useful for draw.DrawText though as that function will expand on newlines for those wanting to use it.

  15. TheDigitallyINSANE says

    getting this error in console friend " [ERROR] gamemodes/stalkerv2/gamemode/stalkerv2hud.lua:5: attempt to call field 'add' (a nil value) 1. unknown – gamemodes/stalkerv2/gamemode/stalkerv2hud.lua:5 2. include – [C]:-1 3. unknown – gamemodes/stalkerv2/gamemode/cl_init.lua:2 "

  16. Willy R says

    hey i am starting to create my own gamemode but i am stuck on the hide HUD partso i was just wondering if you can help me sort out this thing?

  17. Wessel de Wolf says

    [ERROR] gamemodes/zombie/gamemode/testhud.lua:7: '}' expected near ')' 1. unknown – gamemodes/zombie/gamemode/testhud.lua:0 i have got this?=======================================function HUD()endhook.Add("HUDPaint" , "testhud", HUD)function HideHud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end endendhook.Add("HUDShouldDraw", "HideDefaultHUD", HideHud)

  18. Tjis says

    Can you make a addon aswell by following this code?

  19. Hipster Dolphin says

    Hey, I don't know if you still make videos but if you could please do a tutorial on how to make a Player randomizer where it chooses a random player to be it. <— Like in Hide and Seek! Also could you make a tutorial on how to make it to where when a player tags you, you freeze in place and go into spectator mode then when you get tagged by a runner you get unfrozen. I'm trying to make a FreezeTag gamemode… even though one was already made, in my own vision.

  20. Rubén Ortiz says

    Hey man nice videos! i hope you're still over here, i have a little question…I want to make a function that when you kill someone x times it's going to give you another weapon, like arms race in cs:go, that it has an order, could you help me given me a bare idea of the code? i would be very thankful ^^

  21. Dr. Drizzy says

    everytime i goto reload the map i still see the default hud and get this error;[ERROR] gamemodes/dmrp/gamemode/hud.lua:13: unfinished string near '<eof>' 1. unknown – gamemodes/dmrp/gamemode/hud.lua:0this Gyazo shows what i typed in;

  22. craZy_y0 says

    Please say you're still on here. I seriously need help with hiding the HUD and this is beginning to frustrate me now…My HUD refuses to hide. cl_init.lua is as shown:include("shared.lua")include("testhud.lua")init.lua is as shown:AddCSLuaFile("cl_init.lua")AddCSLuaFile("shared.lua")AddCSLuaFile("testhud.lua")include("shared.lua")and testhud.lua is as shown:function HUD() endhook.Add("HUDPaint", "TestHud", HUD) function HideHud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end endendhook.Add("HudShouldDraw", "HideDefaultHud", HideHud)Do you have any idea where I've gone wrong for this to happen? Thanks in advance, hope this can be fixed asap.

  23. thetruemystic_ says

    The health part of the HUD won't hide, heres my code:function HideHud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end endendhook.Add("HUDShouldDraw", "HideDefaultHud", Hidehud)

  24. Justin Little says

    Hey man would you be willing to help me make my own custom gamemode? I would pay?

  25. Tommy J says

    [ERROR] gamemodes/tommy/gamemode/testhud.lua:6: '=' expected near 'function'  1. unknown – gamemodes/tommy/gamemode/testhud.lua:0Code =

  26. Keyboardstalker says

    [ERROR] gamemodes/horde/gamemode/hordehud.lua:8: Tried to use a NULL entity! 1. Health – [C]:-1 2. v – gamemodes/horde/gamemode/hordehud.lua:8 3. unknown – lua/includes/modules/hook.lua:84

  27. The Basic says

    Engine Error Error Loading gamemode: !IsValidGamemode [gamemods]Please HELP

  28. Federico Masi says

    Hey, i really like your videos, but i can't understand how to use those files with a dedicated server instead of a server launched from the game.I tried to do it and everytime that i launch the server i get those errors[AddCSLuaFile] Couldn't find 'cl_init.lua' (@gamemodes/gametest/gamemode/init.lua (line 1))[AddCSLuaFile] Couldn't find 'slared.lua' (@gamemodes/gametest/gamemode/init.lua (line 2))Couldn't include file 'shared.lua' (File not found) (@gamemodes/gametest/gamemode/init.lua (line 4))And when i connect to the server i get this error:[Pandoro|2|STEAM_0:1:53496553] Lua Error:Couldn't include file 'shared.lua' (File not found) (@gamemodes/gametest/gamemode/cl_init.lua (line 1))So the files are where they are supposed to be, all in the same folderIs it possible to get some help from you?If you have some time i'll leave here my skype so you can write at me skype: fede2256If you prefer to speak on discord, i'll leave the link to a server 😛

  29. Johni Clark says

    when i comment out the hud paint part the hud is gone, but when put the hud paint part in, i see the default hl2 hudmy code:

  30. Candy Man says

    hud not disipearing new, hud not showing, and no weapons PLEASE HELP

  31. TheItzAidan says

    shared.lua Error when I try to get my HUD Enabled the error says [ERROR] gamemodes/scgcustom/gamemode/shared.lua:8: '<name>' expected near '=' 1. unknown – gamemodes/scgcustom/gamemode/shared.lua:0

  32. Montess says new hud wont show for some reason

  33. churfire smith says

    FIXED It doesn't let me hide it, and I don't get any errors. Can you please help me?edit: omg, i went over it over and over and just restarted the tutorial, I forgot to capitalize HUDShouldDraw. Awesome video, thank you!

  34. WoWbob396 says

    Your videos are incredible man! They are so in depth and well explained I really appreciate the work!!

  35. Billiam says

    these videos are really helpful but i have a problem. on the eighth line of coding where it says if name — v then the — makes it and everything after it on that line grey including the then. Here is my code if you can find what seems to be wrong with it

  36. Callum's Quotes says

    For another series could you do a tutorial on how someone could code an admin mod? A bit like ULX. That'd be ace!

  37. Otis says

    Plz Help don't know what to do?[ERROR] gamemodes/test/gamemode/testhud.lua:9: Tried to use a NULL entity!  1. Health – [C]:-1   2. v – gamemodes/test/gamemode/testhud.lua:9    3. unknown – lua/includes/modules/hook.lua:84

  38. Bronson Newton says

    My hud won't hide 🙁 :

  39. Sweaty Cubes says

    this might sound strange but i need a way to hide the custom hud just like we hid the default hud. Thanks.

  40. my_hat_stinks says

    You really should not be using hook.Add at all in a gamemode, you should be using the GM functions directly. Your functions are also global here, which is a bad practice even if they weren't so generically named. That's just asking for addon conflicts.I can excuse using a loop instead of a proper lookup table as it's easier to explain, but using a pairs loop instead of a standard for loop when the table is consecutive numeric indices? That's just inefficiency for the sake of inefficiency.

  41. Andrew900460 says

    my crosshair disappears aswell :/why would it disappear?EDIT: If I comment out the GM:HUDShouldDraw(name) method, the hud paints the rectangle and text and the default hud, but when I bring it back it doesn't draw anything, including the custom stufffunction GM:HUDPaint()    local client = LocalPlayer()    if !client:Alive() then        return    end    draw.RoundedBox(0,0,ScrH() – 100, 250, 100,Color(50,50,50,225))    draw.SimpleText("Health: "..client:Health(), "DermaDefaultBold",10,ScrH()-90,Color(255,255,255,240),0,0)endfunction GM:HUDShouldDraw(name)    for k, v in pairs({"CHudHealth","CHudBattery","CHudAmmo","CHudSecondaryAmmo"}) do        if name == v then            return false        end    endend

  42. Synix says

    This Hide Code work too!local hide = {    CHudHealth = true,    CHudBattery = true,}hook.Add( "HUDShouldDraw", "HideHUD", function( name )    if ( hide[ name ] ) then return false end    — Don't return anything here, it may break other addons that rely on this hook.end )

  43. Synix says

    Help!!! NOT WORK!! ;((( CODE :[ERROR] addons/darkrpmodification/lua/autorun/client/cl_testhud.lua:8: ')' expected near 'Color' 1. unknown – addons/darkrpmodification/lua/autorun/client/cl_testhud.lua:0

  44. Horror Player says

    I tried hiding the HUD and its not working what do I do?

  45. SG|Gamer says

    So for me, the hide hud desn't work when I put it on testhud.lua. But if I take the function and throw it in sv_init, my hud is hidden. I did the include and AddCSLuaFile correctly, it's just not calling the file it seems.

Leave A Reply

Your email address will not be published.