Questions tagged [garrys-mod]

Garry's Mod is a sandbox game based around player created content. Only post questions relating to game modding. For questions relating to game play, see gaming.stackexchange.com.

Garry's Mod is a sandbox game that allows users to use the Lua scripting language to create custom addons, such as weapons, NPCs, etc.

Questions tagged with relate to creating addons for Garry's Mod using Lua.

198 questions
1
vote
1 answer

Lua set cooldown for reload

I have this set in my lua reload section and I'd love to set a cooldown function for it like how there is for primaryfire and secondary fire. Is there anyway to do that? Here's my code. function SWEP:Reload() if Chaos == 0 then Chaos =…
Sacred Myths
  • 13
  • 1
  • 5
1
vote
3 answers

How to get out a variable from a function?

So, I'm trying to get a variable out of a function. I have a Garry's Mod script which contains this statement: http.Fetch("http://google.fr", function(body) return body end) My question is: how to retrieve my body variable out of this? I think…
GilDev
  • 514
  • 5
  • 14
1
vote
1 answer

Error: attempt to index local 'self' (a nil value)

I am following a tutorial on Lua, specifically for making a gamemode in the game Garry's Mod. I've been looking at this for a while and I simply can't find what's wrong. function ply:databaseFolders() return "server/example/players/" ..…
cid
  • 447
  • 2
  • 7
  • 15
1
vote
1 answer

I can't run my code?

i made a script for garry's mode, using lua to code a script that allows me to when i bind a key, it will do a jump, then a 360 turn and shoot, but when i finished coding it, it won't let me run a test on it, why is this, and can you by chance tell…
WetCactus
  • 11
  • 1
  • 4
1
vote
2 answers

Lua attempt to index global 'self' error (GMod Lua script)

I have been getting the following error with this section of code: [ERROR] lua/entities/cook/init.lua:58: attempt to index global 'self' (a nil value)1. cooked - lua/entities/cook/init.lua:58 The function starts at line 57, and when I remove line…
user3751712
  • 13
  • 1
  • 3
1
vote
1 answer

What's wrong with my gun?

The error I get is [ERROR] addons/armory station pack/lua/weapons/money_test.lua:31: attempt to call field 'Create' (a nil value) 1. unknown - addons/armory station pack/lua/weapons/money_test.lua:31 My gun code is here. SWEP.PrintName =…
JustinLua
  • 93
  • 5
1
vote
1 answer

How to fix cooldown for Garry's Mod weapon? (attempt to compare nil with number)

I'm making a weapon in Garry's Mod that has three functions that use both mouse buttons and the R key. Since Garry is cool, I was able to easily set the delay for the mouse button attacks with SetNextPrimaryFire() and SetNextSecondaryFire().…
Isaac York
  • 11
  • 2
0
votes
0 answers

Unpack gma files

When I move the addon for the Garry's mod with the gma extension to gmad.exe, the command line flickers for a second and nothing else happens, the files are not unpacked, can anyone know why? Please help me to solve this problem
0
votes
0 answers

"attempt to call a nil value (global 'include')"

i have this code : include("autorun/sh_myaddon.lua") local myName = "Jakub" local age = 999 print(myName) print(age) When i pressed f7 this showned up : lua: ...rrysmod\addons\myaddon\lua\autorun\server\sv_myaddon.lua:1: attempt to call a nil value…
0
votes
0 answers

Gmod: When processing a Net request created from a vgui button, the script does not work

I have 2 scripts: 1)init.lua - server script that handles net requests. 2) change_team.lua - client script that handles vgui buttons and sends net requests. Problem: When pressing the DButton2 button in an attempt to send a net request, an error…
Fix Egg
  • 1
  • 1
0
votes
0 answers

GMOD LUA: Can't set random player model

local models = { "models/player/odessa.mdl", "models/player/alyx.mdl" -- any so on... } hook.Add("PlayerSetModel", "RandomPlayerModel", function(ply) -- Pick a random model based on the array's length local random_model =…
Fix Egg
  • 1
  • 1
0
votes
0 answers

How to fix nextbot on Garry's Mod (non steam)

Can you help me fix the error in the Garry's Mod (.lua) file. I installed the nextbot mod and when I click spawn it shows me "something is creating script errors". As I approach, he suddenly kills me, but is invisible and makes no sound …
konrad
  • 9
  • 2
0
votes
1 answer

Bullet from my SWEP killing NPC, not the player, it means that GM:OnNpcKilled() don't work properly

GM:OnNpcKilled() don't work properly because killer of the NPC isn't a player, how it should be. Instead it is a bullet here's my part of code that creating bullet for SWEP: local Bullet = {} Bullet.Num = self.Primary.NumShots …
0
votes
1 answer

Gmod Lua: Setting a NetworkVar on the Client Side

Whenever I set a networkvar form the client side and then get the networkvar from both sides it returns: Client Side: new value server Side: old value Where as If I set it from the server side, both update like normal: Client Side: new value server…
0
votes
0 answers

Running "RecomputeTargetPath()" causes Garry's Mod to crash

So I have been coding a nextbot in Gmod for a while now and have found a bug that causes Gmod to crash every time the function is run. here is the function: function ENT:RecomputeTargetPath(path_target) if self.testmode then …
Santrix
  • 1
  • 1